Switch cases with only one Cron Job?

async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {

/*
*/

const currentMinute = new Date().getMinutes();
// cron - 0,3,6,9,12,15 0,12 * * *
switch (currentMinute) {
case 0:
await manageVectorEmbeddings();
break;
case 3:
await add_top_10_news();
break;
case 6:
await add_business_news();
break;
case 9:
await add_politics_news();
break;
case 12:
await add_sports_news();
break;
case 15:
await add_technology_news();
break;
}
async scheduled(event: ScheduledEvent, env: Env, ctx: ExecutionContext): Promise<void> {

/*
*/

const currentMinute = new Date().getMinutes();
// cron - 0,3,6,9,12,15 0,12 * * *
switch (currentMinute) {
case 0:
await manageVectorEmbeddings();
break;
case 3:
await add_top_10_news();
break;
case 6:
await add_business_news();
break;
case 9:
await add_politics_news();
break;
case 12:
await add_sports_news();
break;
case 15:
await add_technology_news();
break;
}
Can I rely on this?
1 Reply
Cyb3r-Jak3
Cyb3r-Jak33mo ago
It would be better to do the switch on the cron expression which you can get with event.cron https://developers.cloudflare.com/workers/runtime-apis/handlers/scheduled/#properties
Cloudflare Docs
Scheduled Handler · Cloudflare Workers docs
When a Worker is invoked via a Cron Trigger, the scheduled() handler handles the invocation.
Want results from more Discord servers?
Add your server