Schedule execution: Cron jobs
schedule periodic code execution
To define a schedule, we set both the periodicity and the timezone. We set the periodicity, we use strings such as every day 00:00 or every 8 hours. Then we also provide the callback function.
export const updateRankingsCRON = onSchedule(
{
schedule: "every day 00:00",
timeZone: "Europe/Paris",
region: "europe-west1",
},
async () => {
// ...
}
)
The former version (v1) uses a different API:
export const updateRankingsCRON = functions.pubsub
.schedule("every 8 hours")
.timeZone("Europe/Paris")
.onRun(async (context) => {
// ..
})