diff --git a/apps/cron/20260201-000000/lib/discovery.ts b/apps/cron/20260201-000000/lib/discovery.ts index 6eb69a4..3cb268f 100644 --- a/apps/cron/20260201-000000/lib/discovery.ts +++ b/apps/cron/20260201-000000/lib/discovery.ts @@ -1,10 +1,12 @@ -import { readdir } from 'fs/promises' +import { readdir, readFile } from 'fs/promises' import { existsSync } from 'fs' import { join } from 'path' import { isValidSchedule, toCronExpr, type CronJob, type Schedule } from './schedules' const APPS_DIR = process.env.APPS_DIR! +const SCHEDULE_RE = /export\s+const\s+schedule\s*=\s*['"]([^'"]+)['"]/ + export async function getApps(): Promise { const entries = await readdir(APPS_DIR, { withFileTypes: true }) const apps: string[] = [] @@ -38,8 +40,15 @@ export async function discoverCronJobs(): Promise { const name = file.replace(/\.ts$/, '') try { - const mod = await import(filePath) - const schedule = mod.schedule as Schedule + const source = await readFile(filePath, 'utf-8') + const match = source.match(SCHEDULE_RE) + + if (!match) { + console.error(`No schedule export found in ${filePath}`) + continue + } + + const schedule = match[1] as Schedule if (!isValidSchedule(schedule)) { console.error(`Invalid schedule in ${filePath}: ${schedule}`)