feat: Scheduled Maintenance feature complete
This commit is contained in:
38
backend/src/core/scheduler/index.ts
Normal file
38
backend/src/core/scheduler/index.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @ai-summary Centralized cron job scheduler
|
||||
* @ai-context Uses node-cron for scheduling background tasks
|
||||
*/
|
||||
|
||||
import cron from 'node-cron';
|
||||
import { logger } from '../logging/logger';
|
||||
import { processScheduledNotifications } from '../../features/notifications/jobs/notification-processor.job';
|
||||
|
||||
let schedulerInitialized = false;
|
||||
|
||||
export function initializeScheduler(): void {
|
||||
if (schedulerInitialized) {
|
||||
logger.warn('Scheduler already initialized, skipping');
|
||||
return;
|
||||
}
|
||||
|
||||
logger.info('Initializing cron scheduler');
|
||||
|
||||
// Daily notification processing at 8 AM
|
||||
cron.schedule('0 8 * * *', async () => {
|
||||
logger.info('Running scheduled notification job');
|
||||
try {
|
||||
await processScheduledNotifications();
|
||||
} catch (error) {
|
||||
logger.error('Scheduled notification job failed', {
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
schedulerInitialized = true;
|
||||
logger.info('Cron scheduler initialized - notification job scheduled for 8 AM daily');
|
||||
}
|
||||
|
||||
export function isSchedulerInitialized(): boolean {
|
||||
return schedulerInitialized;
|
||||
}
|
||||
Reference in New Issue
Block a user