feat(ext/cron): scaffold Deno.cron.persistent API (no backends yet)#33965
feat(ext/cron): scaffold Deno.cron.persistent API (no backends yet)#33965bartlomieju wants to merge 1 commit into
Conversation
First step toward persistent cron jobs that survive process exit and reboot via the host OS scheduler. Lands the public API surface and Rust wiring only; all backends return "unsupported on this platform". Adds `Deno.cron.persistent`, `Deno.cron.remove`, `Deno.cron.list` as namespace-attached methods on the existing `Deno.cron` function, plus a new `Deno.CronController` type for the worker entry point's `default.scheduled` callback. The `deno_cron` extension grows a second generic parameter `P: PersistentCronHandler` and a stub `PersistentCronHandlerImpl::Unimplemented` variant; all four `deno_cron::init` call sites pass it through. Gated behind the existing `--unstable-cron` flag.
fibibot
left a comment
There was a problem hiding this comment.
Spec test tests/specs/run/unstable_cron_enabled is broken on every platform (Linux/macOS/Windows, debug + release). The test does console.log(scope, Deno.cron) and unstable_cron.enabled.out expects:
main [Function: cron]
worker [Function: cron]
but 01_cron.ts now unconditionally attaches persistent, remove, list to the function, so the actual output is main [Function: cron] { persistent: ..., remove: ..., list: ... }. Update the .out file to match.
Separately: the new surface has no positive test. Even with every backend returning Unsupported, a spec test that exercises Deno.cron.persistent(...) and asserts on the persistent cron is not yet supported on this platform error would lock in the JS-side validation paths (TypeError on missing name/schedule/script, non-string env values, etc.) before the per-OS backends land.
- nit:
op_cron_persistent_createcallsvalidate_cron_name(≤ 64 chars), but JS-sidepersistent()only checkslength > 0. The Rust error still surfaces, just less consistently than the other TypeErrors thrown from JS. - nit:
permissions: string[]flows straight through to whatever follow-up backend will exec the worker. Worth deciding now whether anything other than--allow-*/--deny-*is rejected at registration — once a poisoned string is in a user's crontab/launchd plist it's painful to revoke.
|
|
|
|
lunadogbot
left a comment
There was a problem hiding this comment.
tests/specs/run/unstable_cron_enabled/unstable_cron.enabled.outstill expectsmain [Function: cron]/worker [Function: cron], but01_cron.tsnow attachespersistent,remove, andlisttoDeno.cron. Thetest specs (1/2)failures are real; update the fixture to match the new inspected function shape.Deno.cron.persistent,Deno.cron.remove, andDeno.cron.listadd public unstable API with no spec/unit coverage. Even while every backend returns unsupported, add a test that runs with--unstable-cronand covers the exposed methods plus the current unsupported error path.
- nit: the new JSDoc blocks in
lib.deno.unstable.d.tsdo not include@param/@returnsforpersistent,remove, orlist.
First step toward persistent cron jobs in Deno — jobs that survive
process exit and reboot because they are registered with the host OS
scheduler (crontab on Linux, launchd on macOS, schtasks on Windows)
rather than kept alive by an in-process tokio loop. This PR lands the
public API surface and the Rust wiring only; every backend currently
returns "persistent cron is not yet supported on this platform". Per-OS
backends and the
deno cron execsubcommand that the OS schedulerinvokes will follow in separate PRs.
Deno.cron.persistent,Deno.cron.remove, andDeno.cron.listarenamespace-attached methods on the existing
Deno.cronfunction, so theycompose with the in-memory cron API. The worker entry point exports
default.scheduled(controller)matching the Cloudflare Workers CronTriggers shape. On the Rust side the
deno_cronextension gains asecond generic
P: PersistentCronHandler; for now only anUnimplementedvariant exists, returningCronError::Unsupportedfromevery method. Gated behind the existing
--unstable-cronflag.