36 lines
1.1 KiB
JavaScript
36 lines
1.1 KiB
JavaScript
import cron from 'node-cron';
|
|
import { runSync } from './sync_source_docs.js';
|
|
import { log } from '../log.js';
|
|
import { enqueue } from '../jobs/queue.js';
|
|
import { load } from '../health/registry.js';
|
|
import { checkAll } from '../health/checker.js';
|
|
import * as statusRepo from '../db/repos/service_status.js';
|
|
|
|
export function startCron() {
|
|
// Daily at 03:00 local time
|
|
cron.schedule('0 3 * * *', async () => {
|
|
try {
|
|
const n = await runSync();
|
|
log.info({ enqueued: n }, 'cron sync.source_doc complete');
|
|
} catch (e) {
|
|
log.error({ err: e }, 'cron sync.source_doc failed');
|
|
}
|
|
});
|
|
|
|
// Hourly speedtest
|
|
cron.schedule('0 * * * *', async () => {
|
|
try { await enqueue('speedtest', {}); log.info('cron speedtest enqueued'); }
|
|
catch (e) { log.error({ err: e }, 'cron speedtest failed'); }
|
|
});
|
|
|
|
cron.schedule('*/1 * * * *', async () => {
|
|
try {
|
|
const results = await checkAll(load());
|
|
for (const r of results) await statusRepo.upsert(r);
|
|
log.info({ n: results.length }, 'health check complete');
|
|
} catch (e) { log.error({ err: e }, 'health check failed'); }
|
|
});
|
|
|
|
log.info('cron started');
|
|
}
|