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');