Home > Net >  How to schedule a function in firebase that is run approximately every full hour?
How to schedule a function in firebase that is run approximately every full hour?

Time:10-28

The firebase documentation explains how to configure a function to be run every 5 minutes. I would like to run a function fairly precisely every full hour. I could easily schedule it to run once per hour, but how is it possible to have it run at the full hour, 8:00, 9:00, ....

I am prepared that it will run only approximately at full hour.

CodePudding user response:

Instead of using English description for the schedule, use what is called
"unix-cron string format" (* * * * *) where you could specify exact(or repeated) min, hour, day, month, or day of the week fo the schedule.

This link for "Configuring cron job schedules" : https://cloud.google.com/scheduler/docs/configuring/cron-job-schedules

And this article explain both of them: English description and unix-cron string format: https://firebase.googleblog.com/2019/04/schedule-cloud-functions-firebase-cron.html

Eventually you function should look like this:

exports.testFunction = functions
     .pubsub.schedule('0 * * * *') // every hour at the 0 min, every day, every month 
     .onRun(...//the code to run);
  • Related