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’);
});
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.
- 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!)
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.
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?