/*********************************************************************************************************************************************************************** * File Name : admin.cron.js * Type : Cron Registry — Admin side * Description : Aggregates and registers every admin-facing scheduled job. * Each job module in cron/jobs/ exports { name, schedule, run }: * name {string} – unique identifier, used in logs * schedule {string} – standard cron expression (node-cron) * run {function} – async () => void, the actual work * * To add a new admin-side cron job: * 1. Create cron/jobs/yourJob.cron.js exporting * { name, schedule, run } * 2. require() it below and add it to the `jobs` array * That's the only wiring required — server.js never needs to * change when admin-side jobs are added/removed. * * taskOverdue is settings-backed (see cronRegistry.util.js) — * its schedule/enabled state lives in cron_notification_settings * and is configurable from /admin/notifications/settings without * a restart. liftExpiredBans is not notification-related, so it * stays on a plain hardcoded schedule. * * Currently registered: * - taskOverdue (cron/jobs/task_overdue.cron.js) — settings-backed * - liftExpiredBans (cron/jobs/lift_expired_bans.cron.js) * - dispatchEmailBroadcasts (cron/jobs/dispatch_email_broadcasts.cron.js) * * Author: Kenneth Obsequio (@lash0000) * Date Created: Jun. 17, 2026 ***********************************************************************************************************************************************************************/ const cron = require('node-cron'); const taskOverdue = require('./jobs/task_overdue.cron'); const liftExpiredBans = require('./jobs/lift_expired_bans.cron'); const dispatchEmailBroadcasts = require('./jobs/dispatch_email_broadcasts.cron'); const { startSettingsBackedJobs } = require('./cronRegistry.util'); // ─── Registry — add future admin-side cron jobs here ───────────────────────── const settingsBackedJobs = [ taskOverdue, ]; // Plain hardcoded-schedule jobs (not tied to any notification setting). const plainJobs = [ liftExpiredBans, dispatchEmailBroadcasts, ]; // ─── Boot all registered admin-side jobs ────────────────────────────────────── async function startAdminCronJobs() { const registered = await startSettingsBackedJobs(settingsBackedJobs, 'ADMIN'); for (const job of plainJobs) { if (!cron.validate(job.schedule)) { console.error(`[CRON][ADMIN] Invalid schedule for "${job.name}": "${job.schedule}" — skipped.`); continue; } cron.schedule(job.schedule, job.run); registered.push({ name: job.name, scope: 'ADMIN', schedule: job.schedule }); } return registered; } module.exports = { startAdminCronJobs };