- monitored_services table (mig 015) replaces config/services.json (now a boot seed) - owner CRUD over /api/health/services; GET is DB-backed; cron+worker read the DB - discover.lan worker: pure-Node TCP sweep + HTTP-title probe -> disabled 'discovered' candidates (never clobbers curated entries); POST /api/health/discover + GET .../discovered - dashboard: Scan button + Discovered(N) section with one-click promote Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
40 lines
1.5 KiB
JavaScript
40 lines
1.5 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 { checkAll } from '../health/checker.js';
|
|
import * as statusRepo from '../db/repos/service_status.js';
|
|
import * as services from '../db/repos/monitored_services.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'); }
|
|
});
|
|
|
|
// Health checks every minute. NOTE: this runs checkAll() inline; the same
|
|
// probe+upsert logic is also exposed on-demand via the `health.check` pg-boss
|
|
// worker (lib/jobs/workers/health_check.js, triggered by POST /api/health/check).
|
|
// Keep the two in sync — both rely on lib/health/checker.js as the source of truth.
|
|
cron.schedule('*/1 * * * *', async () => {
|
|
try {
|
|
const results = await checkAll(await services.listEnabled());
|
|
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');
|
|
}
|