Replies: 2 comments 7 replies
-
I'm not sure what you meant by "cronjob", but Hono is a slim framework, almost like a router, so it doesn't have a cron function. However, if you were referring to Cloudflare Triggers, you can write it as follows: export default {
fetch: app.fetch,
async scheduled(event, env, ctx) {
ctx.waitUntil(doSomeTaskOnASchedule())
}
} |
Beta Was this translation helpful? Give feedback.
-
I got this working nicely with something like this (in typescript): note that cronTask is just a function called on the cron schedule. You can use whatever works for you. I use the waitUntil method so I can guarantee to finish the cronTask function processing before the cloud function is terminated (all of this is running on Cloudflare workers): export default {
/** this part manages cronjobs */
scheduled(
event: ScheduledEvent,
env: {
DB?: any;
SENDGRID_API_KEY: any;
},
ctx: ExecutionContext
) {
const delayedProcessing = async () => {
await cronTask(env);
};
ctx.waitUntil(delayedProcessing());
},
/** this part manages regular REST */
fetch(request: Request, env: Env, ctx: ExecutionContext) {
return app.fetch(request, env, ctx);
},
}; in plain JS this should look something like this (js code untested): export default {
scheduled(event, env, ctx) {
const delayedProcessing = async () => {
await cronTask(env)
}
ctx.waitUntil(delayedProcessing())
},
fetch(request, env, ctx) {
return app.fetch(request, env, ctx)
}
} |
Beta Was this translation helpful? Give feedback.
-
How can I create cronjob in Hono guys?
Beta Was this translation helpful? Give feedback.
All reactions