Created
April 18, 2022 20:51
-
-
Save magician11/23cacfa95fc6b7a25b4c55a8b662225b to your computer and use it in GitHub Desktop.
How to conditionally schedule a Firebase pubsub function depending on the Firebase account
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const productionFirebaseAccount = 'production-firebase-account'; | |
if (process.env.GCLOUD_PROJECT === productionFirebaseAccount) { | |
exports.generateInvoices = functions.pubsub | |
.schedule('0 15 * * 5') // every Friday at 3pm PST | |
.timeZone('America/Vancouver') | |
.onRun(async context => { | |
const generateInvoices = require('./reports/generateInvoices'); | |
await generateInvoices(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Our scenario, is basically if we have a production and development Firebase account, I only want the scheduled functions (pubsubs) for running say reports, to run on the production account so the team doesn't get doubled-up invoices.
So the above code setup ensures only the production Firebase account gets the pubsubs deployed to it, by conditionally exporting the pubsub depending on the Firebase project/account by referencing the GCLOUD_PROJECT reserved environment variable.