mirror of
https://github.com/tiennm99/miti99bot.git
synced 2026-04-17 13:21:31 +00:00
2.1 KiB
2.1 KiB
Phase 02 Report — Cron Wiring
Files Modified/Created
- Created
src/modules/validate-cron.js— validates{ name, schedule, handler }entries; 5/6-field cron regex check - Created
src/modules/cron-dispatcher.js—dispatchScheduled(event, env, ctx, registry)fan-out with per-handler try/catch - Modified
src/modules/registry.js— addedvalidateCronimport; cron validation + duplicate-name check inloadModules;CronEntry[]collection inbuildRegistry;registry.cronsexposed in typedef and return value - Modified
src/bot.js— addedgetRegistry(env)export; shares same memoized registry withfetchhandler - Modified
src/index.js— addedscheduled(event, env, ctx)export; callsgetRegistrythendispatchScheduled - Modified
wrangler.toml— added[triggers] crons = []placeholder with authoring instructions - Created
tests/modules/validate-cron.test.js— 9 tests (valid entry, bad name, bad schedule, bad handler) - Created
tests/modules/cron-dispatcher.test.js— 6 tests (schedule match, no-match, fan-out, error isolation, ctx pass-through, empty registry) - Modified
tests/modules/registry.test.js— added 6 cron collection tests (empty, collect, fan-out, duplicate name, non-array, invalid entry)
Tests
- All 139 tests pass (
14 passedfiles) - 0 new lint errors introduced (17 eslint errors are pre-existing: KVNamespace/D1Database/Request undefined types + CRLF line-ending biome format noise from Windows git autocrlf)
Deviations
getRegistry(env)added tobot.jsrather than importingbuildRegistrydirectly inindex.js— avoids bypassing the Bot init path and ensures single shared memoized registry acrossfetch+scheduled.- Test fixture module names use kebab-case (
mod-a,mod-b) to satisfycreateStore's^[a-z0-9_-]+$constraint (initial camelCase caused 2 failures, fixed immediately).
Status: DONE
Summary: Cron Triggers wired end-to-end — module contract extended with crons[], dispatcher dispatches per schedule, registry collects + validates, scheduled() exported from worker entry. All tests green, no new lint issues.