When I try to deploy my newly created Firebase PubSub function, I get the error Error: Failed to create scheduler job projects/workouts-uat/locations/europe-west1/jobs/firebase-schedule-dailyTasks-eur3: HTTP Error: 400, Schedule or time zone is invalid.
My function is declared as follows:
exports.dailyTasks = functions
.region('europe-west2')
.pubsub
.schedule('every 24 hours 00:00')
.timeZone('Africa/Johannesburg')
.onRun(...);
From my research I found that that the region used should be the same as the region found in your project settings, which in my case is eur3 (europe-west)
. All my existing onCall
functions use europe-west2
which is why I tried to go with that first, but after finding my project settings region I updated to .region('eur3')
and .region('europe-west')
, but the error persists. So how do I successfully deploy this function?
Another hint I came across while googling the error was that a "Google App Engine (GAE) app" has to be created for pubsub functions to work, but I'm assuming that happens automatically on function deploy, right? Otherwise how does one create that? I have zero experience with GCP.
When I try to deploy my newly created Firebase PubSub function, I get the error Error: Failed to create scheduler job projects/workouts-uat/locations/europe-west1/jobs/firebase-schedule-dailyTasks-eur3: HTTP Error: 400, Schedule or time zone is invalid.
My function is declared as follows:
exports.dailyTasks = functions
.region('europe-west2')
.pubsub
.schedule('every 24 hours 00:00')
.timeZone('Africa/Johannesburg')
.onRun(...);
From my research I found that that the region used should be the same as the region found in your project settings, which in my case is eur3 (europe-west)
. All my existing onCall
functions use europe-west2
which is why I tried to go with that first, but after finding my project settings region I updated to .region('eur3')
and .region('europe-west')
, but the error persists. So how do I successfully deploy this function?
Another hint I came across while googling the error was that a "Google App Engine (GAE) app" has to be created for pubsub functions to work, but I'm assuming that happens automatically on function deploy, right? Otherwise how does one create that? I have zero experience with GCP.
Share Improve this question edited Apr 29, 2021 at 19:26 SeriousLee asked Apr 13, 2021 at 17:42 SeriousLeeSeriousLee 1,3715 gold badges24 silver badges47 bronze badges2 Answers
Reset to default 8I finally figured this out. It had nothing to do with the .timeZone()
, as I originally thought - it was an error with the .schedule()
. And yes, I just saw that the error message does include the possibility that it could be the "Schedule or time zone", but for some reason I thought it was referring to the function as a whole and not the .schedule()
call.
In any case, once I updated my every 24 hours 00:00
to every day 00:00
, it all of a sudden deployed just fine. For clarity, this is what my working function signature now looks like:
exports.dailyTasks = functions
.region('europe-west2')
.pubsub
.schedule('every day 00:00')
.timeZone('Africa/Johannesburg')
As it turns out, .region()
also had nothing to do with it, and europe-west2
works just fine.
I'd like to thank the author of this article, because he linked an example project that also calls a pubsub function every day at midnight, and without said article, I'd have never found the answer.
I was having significant issues getting it to accept a schedule. I ended up finding this list of valid schedules (copied below)
Schedule | Cron Job Format | Explanation |
---|---|---|
Every minute | * * * * * |
Runs on the minute. For example, 9:00 AM, 9:01 AM, :02 AM, and so on. |
Every hour | 0 * * * * |
Runs on the hour. For example, 9:00 AM, 10:00 AM, 11:00 AM, and so on. |
Every day | 0 0 * * * |
Runs at 12:00 AM (00:00 in 24-hour format) every day. |
Every weekday | 0 0 * * 1-5 |
Runs at 12:00 AM (00:00 in 24-hour format) on Mondays, Tuesdays, Wednesdays, Thursdays, and Fridays. |
Every week | 0 0 * * 0 |
Runs on Sundays at 12:00 AM (00:00 in 24-hour format). |
Every month | 0 0 1 * * |
Runs at 12:00 AM (00:00 in 24-hour format) on the first day of the month. |
Every quarter | 0 0 1 1,4,7,10 * |
Runs at 12:00 AM (00:00 in 24-hour format) on the first day of the quarter: January 1st, April 1st, July 1st, and October 1st. |
Every year | 0 0 1 1 * |
Runs at 12:00 AM (00:00 in 24-hour format) on the first day of the first month of the year (January 1st). |