EthanThatOneKid
EthanThatOneKid15mo ago

Denoflare scheduled workers

Cloudflare has a cronjob feature for running workers at a scheduled time. Wrangler has a flag wrangler dev --test-scheduled (https://developers.cloudflare.com/workers/runtime-apis/scheduled-event/) allowing users to test their scheduled workers via curl "http://localhost:8787/__scheduled?cron=*+*+*+*+*". I read the Denoflare documentation https://denoflare.dev, but it isn’t very clear how to develop scheduled workers. cc @John Spurlock
4 Replies
EthanThatOneKid
EthanThatOneKidOP15mo ago
To clarify, are scheduled workers supported by Denoflare? If not, are scheduled workers within the scope of Denoflare?
John Spurlock
John Spurlock15mo ago
just define a scheduled handler alongside your module fetch handler like any other worker. Full signature looks like: scheduled(event: ModuleWorkerScheduledEvent, env: MyWorkerEnv, ctx: ModuleWorkerContext): Promise<void>;
No description
John Spurlock
John Spurlock15mo ago
there's no way to simulate cron events locally - for my workers I just call into common code that's also reachable by an admin endpoint from fetch for easy testing
EthanThatOneKid
EthanThatOneKidOP15mo ago
You are correct, it worked! I was able to create a working scheduled function. However, it required at least the adjacent fetch method. At least for me, I have been helped and my question is resolved <:party_deno:1035517691517218847> Resulting deployed worker: https://github.com/acmcsufoss/lc-dailies/blob/b08b4a98c568872f16bc836eaf674df220d02062/cf/dailies/dailies.ts<:cookie_deno:1002977285734932480>