Skip to content

Instantly share code, notes, and snippets.

@magician11
Created April 18, 2022 20:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magician11/23cacfa95fc6b7a25b4c55a8b662225b to your computer and use it in GitHub Desktop.
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
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();
});
}
@magician11
Copy link
Author

magician11 commented Apr 18, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment