Ad

Why Is My Cron Scheduled Cloud Function For Firebase Running On Pacific Time Rather Than UTC?

I have a Scheduled Cloud Function (using Google's new solution) that is meant to run every Monday at 12:00am.

export const updateHighScores = functions.pubsub.schedule('0 0 * * 1').onRun((context) => {

    // (code)
    // console.log(‘This code will run every Monday at 12:00 AM UTC’);

});

Functions Dashboard

I was expecting it to run at 12:00am UTC; however, when midnight UTC rolled around, nothing happened. So I went to bed, saddened that my scheduled cloud function didn't work, but determined to keep working at it.

But the next day I checked the logs, and it appears it did work, but it ran at 12:00am Pacific time instead.

Functions Log

  • The Cloud Function's region is set to us-central1, but I don't think that affects this.
  • My computer's time zone is set to Pacific time and I'm located in central time, but I wouldn't think either would matter.
  • I also clicked around in Firebase and Google Cloud Platform to see if maybe I had a setting that was affecting it, but didn't find anything.

Any idea why this ran at midnight Pacific time rather than UTC?

(I'm going to do a bunch of guess-and-checking by changing all these variables and observing how it affects the scheduled cloud function, but figured might as well ask here in case someone knows off the top of their head. Thanks!)

Ad

Answer

Scheduled functions are triggered on a scheduled by Google Cloud Scheduler. When deploying with the Firebase CLI, the entry in Cloud Scheduler is automatically created for you. If you click through to the Cloud console to show your schedules, you'll see the timezone is set to "America/Los_Angeles", which is PST.

The timezone is set using the function builder API. You can read about that in the documentation.

Ad
source: stackoverflow.com
Ad