mirror of
https://github.com/ostris/ai-toolkit.git
synced 2026-04-30 19:21:39 +00:00
Initial setup for a cron working on the ui for various tasks
This commit is contained in:
31
ui/cron/worker.ts
Normal file
31
ui/cron/worker.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
class CronWorker {
|
||||
interval: number;
|
||||
is_running: boolean;
|
||||
intervalId: NodeJS.Timeout;
|
||||
constructor() {
|
||||
this.interval = 1000; // Default interval of 1 second
|
||||
this.is_running = false;
|
||||
this.intervalId = setInterval(() => {
|
||||
this.run();
|
||||
}, this.interval);
|
||||
}
|
||||
async run() {
|
||||
if (this.is_running) {
|
||||
return;
|
||||
}
|
||||
this.is_running = true;
|
||||
try {
|
||||
// Loop logic here
|
||||
await this.loop();
|
||||
} catch (error) {
|
||||
console.error('Error in cron worker loop:', error);
|
||||
}
|
||||
this.is_running = false;
|
||||
}
|
||||
|
||||
async loop() {}
|
||||
}
|
||||
|
||||
// it automatically starts the loop
|
||||
const cronWorker = new CronWorker();
|
||||
console.log('Cron worker started with interval:', cronWorker.interval, 'ms');
|
||||
Reference in New Issue
Block a user