Files
starr-philproperties/cron/admin.cron.js
T
2026-08-01 17:44:25 +08:00

65 lines
3.2 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/***********************************************************************************************************************************************************************
* 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)
* - retryStuckTranscodes (cron/jobs/retry_stuck_transcodes.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 retryStuckTranscodes = require('./jobs/retry_stuck_transcodes.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,
retryStuckTranscodes,
];
// ─── 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 };