diff --git a/apps/cron/20260201-000000/index.tsx b/apps/cron/20260201-000000/index.tsx index a0696d4..e6c3fce 100644 --- a/apps/cron/20260201-000000/index.tsx +++ b/apps/cron/20260201-000000/index.tsx @@ -9,7 +9,7 @@ import { SCHEDULES, type CronJob } from './lib/schedules' import type { Child } from 'hono/jsx' import { join } from 'path' import { mkdir, writeFile } from 'fs/promises' -import { existsSync } from 'fs' +import { existsSync, watch } from 'fs' const APPS_DIR = process.env.APPS_DIR! @@ -372,8 +372,10 @@ async function init() { } } -// Re-discover every 60s -setInterval(async () => { +// Watch for cron file changes +let debounceTimer: Timer | null = null + +async function rediscover() { const jobs = await discoverCronJobs() const existing = getAllJobs() @@ -403,7 +405,15 @@ setInterval(async () => { } setJobs(jobs) -}, 60000) +} + +watch(APPS_DIR, { recursive: true }, (_event, filename) => { + if (!filename?.includes('/cron/') && !filename?.includes('\\cron\\')) return + if (!filename.endsWith('.ts')) return + + if (debounceTimer) clearTimeout(debounceTimer) + debounceTimer = setTimeout(rediscover, 100) +}) init()