Multiple Cron Triggers
Set multiple Cron Triggers on three different schedules.
export default {async scheduled(event, env, ctx) {// Write code for updating your APIswitch (event.cron) {// You can set up to three schedules maximum.case "*/3 * * * *":// Every three minutesawait updateAPI();break;case "*/10 * * * *":// Every ten minutesawait updateAPI2();break;case "*/45 * * * *":// Every forty-five minutesawait updateAPI3();break;}console.log("cron processed");},};
const handler: ExportedHandler = {async scheduled(event, env, ctx) {// Write code for updating your APIswitch (event.cron) {// You can set up to three schedules maximum.case "*/3 * * * *":// Every three minutesawait updateAPI();break;case "*/10 * * * *":// Every ten minutesawait updateAPI2();break;case "*/45 * * * *":// Every forty-five minutesawait updateAPI3();break;}console.log("cron processed");},};export default handler;
Test Cron Triggers using Wrangler
The recommended way of testing Cron Triggers is using Wrangler.
Cron Triggers can be tested using Wrangler by passing in the --test-scheduled
flag to wrangler dev
. This will expose a /__scheduled
route which can be used to test using a HTTP request. To simulate different cron patterns, a cron
query parameter can be passed in.
$ wrangler dev --test-scheduled$ curl "http://localhost:8787/__scheduled?cron=*%2F3+*+*+*+*"