Files
Caramel-CRM/resources/js/stores/webcronStore.ts
T

32 lines
856 B
TypeScript

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)
}
})
}
}
})