notify-cron.js
1 #!/usr/bin/env node 2 3 /** 4 * Notify the cron scheduler that a task was just run manually. 5 * Updates last_run_at in cron_jobs so the scheduler skips duplicate runs. 6 * 7 * Usage: node scripts/notify-cron.js <taskKey1> [taskKey2] ... 8 * Example: node scripts/notify-cron.js runTests lintCode 9 */ 10 11 import { createDatabaseConnection } from '../src/utils/db.js'; 12 import { join, dirname } from 'path'; 13 import { fileURLToPath } from 'url'; 14 15 const __dirname = dirname(fileURLToPath(import.meta.url)); 16 const projectRoot = join(__dirname, '..'); 17 const dbPath = process.env.DATABASE_PATH || join(projectRoot, 'db/sites.db'); 18 19 const taskKeys = process.argv.slice(2); 20 21 if (taskKeys.length === 0) { 22 process.exit(0); 23 } 24 25 try { 26 const db = createDatabaseConnection(dbPath); 27 28 for (const taskKey of taskKeys) { 29 const job = db 30 .prepare( 31 'SELECT task_key, name, interval_value, interval_unit FROM ops.cron_jobs WHERE task_key = ?' 32 ) 33 .get(taskKey); 34 35 if (job) { 36 db.prepare("UPDATE ops.cron_jobs SET last_run_at = datetime('now') WHERE task_key = ?").run( 37 taskKey 38 ); 39 console.log( 40 `Cron updated: ${job.name} (won't re-run for ${job.interval_value} ${job.interval_unit})` 41 ); 42 } 43 } 44 45 db.close(); 46 } catch { 47 // Silently ignore - DB may not exist during CI or fresh setup 48 }