toucan-js icon indicating copy to clipboard operation
toucan-js copied to clipboard

scheduled waitUntil() don't report anything (maybe to typo in the README)

Open ismaail opened this issue 2 years ago • 0 comments

From the README, passing a function to context.waitUntil don't seem to work.

export default {
    async scheduled(controller: Controller, env: Env, context: Context) {
        //...
        context.waitUntil(async () => {
            try {
                // Your code
            } catch (err) {
                sentry.captureException(err);
            }
        });
    },
}

From Cloudflare Documentation / ScheduledEvent / Syntax: Module Worker, the function passed to context.waitUntil must be called

export default {
    async scheduled(event, env, ctx) {
        ctx.waitUntil(doSomeTaskOnASchedule());
    },
};

so the code that works:

export default {
    async scheduled(controller: Controller, env: Env, context: Context) {
        //...
        context.waitUntil((async () => {
            try {
                // Your code
            } catch (err) {
                sentry.captureException(err);
            }
        })());
    },
}

  • module (.mjs)
  • wrangler 2.1.6
  • node: v18.9.0
  • OS: ArchLinux

ismaail avatar Sep 22 '22 12:09 ismaail