import cron from 'node-cron'; import { createCorrelationId, runWithCorrelationId } from '../lib/correlation.js'; export function scheduleJobs({ runPendingApprovals, cleanupOldLogs, runWebexOAuthMaintenance, log }) { cron.schedule('0 30 9 * * *', async function () { const correlationId = createCorrelationId({ routeName: 'cron' }); await runWithCorrelationId(correlationId, async () => { try { log.logger('cron', 'Starting scheduled job'); await runPendingApprovals(); await cleanupOldLogs(); log.logger('cron', 'Scheduled job completed'); } catch (error) { log.logError('cron', 'Scheduled job failed', error); } }); }); if (runWebexOAuthMaintenance) { cron.schedule('0 0 8 * * *', async function () { const correlationId = createCorrelationId({ routeName: 'cron-webex-oauth' }); await runWithCorrelationId(correlationId, async () => { try { log.logger('cron', 'Starting Webex OAuth maintenance'); await runWebexOAuthMaintenance(); log.logger('cron', 'Webex OAuth maintenance completed'); } catch (error) { log.logError('cron', 'Webex OAuth maintenance failed', error); } }); }); } }