"Handler does not export a scheduled() function" - No matter how it's exported

Howdy, I'm struggling to use the CRON events for my worker; no matter how I export my scheduled fnc, the worker insists it does not exist. As I understand it, the export must be named exactly scheduled, so in my index.ts I have the following:
export const scheduled = async (controller: ScheduledController, env: Env) => {
console.log('Scheduled function triggered:', controller.cron);
};
export const scheduled = async (controller: ScheduledController, env: Env) => {
console.log('Scheduled function triggered:', controller.cron);
};
Yet when the CRON runs, I get Handler does not export a scheduled() function. If I try using export default then I get errors about the handler not having fetch. If I used a named export for fetch and the default for what would be the scheduled, I get a different error again: No event listener registered for scheduled events.. I feel I'm running in circles lol, any input would be appreciated, thanks.
8 Replies
Cyb3r-Jak3
Cyb3r-Jak3•3w ago
Cloudflare Docs
Scheduled Handler · Cloudflare Workers docs
When a Worker is invoked via a Cron Trigger, the scheduled() handler handles the invocation.
Christopher
ChristopherOP•3w ago
If I try using export default then I get errors about the handler not having fetch.
:NotLikeThis: Any suggestions? 😅 I'll try it again now and get the full error
Cyb3r-Jak3
Cyb3r-Jak3•3w ago
Oh sorry it is late
export default {
async fetch() {}
async scheduled(event, env, ctx) {
ctx.waitUntil(doSomeTaskOnASchedule());
},
};
export default {
async fetch() {}
async scheduled(event, env, ctx) {
ctx.waitUntil(doSomeTaskOnASchedule());
},
};
Christopher
ChristopherOP•3w ago
Ahhh okay, I hadn't tried that, allow me a moment to edit, deploy, and CRON to test, ty! :pray_duck:
Christopher
ChristopherOP•3w ago
:pogfish:
No description
Christopher
ChristopherOP•3w ago
I've been stuck on this for over 4 hours and you solved it in 2 messages, my hero
Cyb3r-Jak3
Cyb3r-Jak3•3w ago
Glad it was a quick fix.
Christopher
ChristopherOP•3w ago
:Prayge: May your pillow always be cold, ty, good evening

Did you find this page helpful?