Schedule Cron jobs
periodic code execution: schedule a Cron job
We schedule a Cron job, with the help of Google Cloud's Cloud Scheduler. We register a job with onSchedule. We set:
- the periodicity, using strings such as
every day 00:00orevery 8 hours. - the timezone (IANA string), the region and the callback function:
export const updateRankingsCRON = onSchedule(
{
schedule: "every day 00:00",
timeZone: "Europe/London",
region: "europe-west1",
},
async () => {
// ...
},
)
The older API (v1) relied on pubsub instead:
export const updateRankingsCRON = functions.pubsub
.schedule("every 8 hours")
.timeZone("Europe/London")
.onRun(async (context) => {
// ..
})