Skip to content Skip to sidebar Skip to footer

Why Does Google Cloud Function Run A Global Function Multiple Times After Deploy?

I have set multiple triggers, like: exports.doSomething = functions.firestore.document('col/{doc}').onCreate(event => {}) Than I have a function that I want to run instant when

Solution 1:

Cloud Functions doesn't provide a way to run a bit of code at the time of deploy. Your function is obviously being run multiple times, and you should expect it to be run even more times as new server instances are allocated (and destroyed) in tandem with the load on your project. This is how Cloud Functions scales. There is definitely not just one server instance handling all your requests. You should expect any global code to be run repeatedly.

If you want to run some code exactly once after deploy, make an exported funciton (maybe HTTPS) and trigger it after you deploy. Maybe you could write a script that both deploys your code then triggers the function with curl or some other mechanism you choose.

Post a Comment for "Why Does Google Cloud Function Run A Global Function Multiple Times After Deploy?"