Add new global pinia webcron store to handle webcron requests. The old implementation would add additional intervals for each page request.

This commit is contained in:
2025-12-09 15:10:04 +01:00
parent 7d9261dd6e
commit 6d03cf1e5d
3 changed files with 37 additions and 15 deletions
-1
View File
@@ -1,4 +1,3 @@
import { options } from '@coders-tm/vue-number-format';
import { defineStore } from 'pinia'
export interface AlertOptions {
+32
View File
@@ -0,0 +1,32 @@
import { defineStore } from 'pinia'
import axios from 'axios';
export const webcronStore = defineStore('webcron', {
state: () => {
return {
timeout: 1000 * 30,
interval: 0,
url: '/webcron'
}
},
actions: {
start() {
if (this.interval) return
this.triggerWebcron(this.url)
this.interval = setInterval(this.triggerWebcron, this.timeout, this.url)
},
stop() {
clearInterval(this.interval)
this.interval = 0
},
triggerWebcron: async (url: string) => {
await axios.get(url)
.catch(function (response) {
if (response.status >= 400) {
console.error(response.message)
}
})
}
}
})