Terminating firebase HTTP function

Is it okay to use extra logic in Firebase HTTPS function after sending the response?

I have functions where this happens:

  • write to Firebase DB
  • Once the entry is complete, I will post a response ( res.status(200 / 500).send()

    called here )
  • I am looking at some FCM tokens in the DB and sending a push message (it doesn't matter from the point of view of the requestor if it's successful or not).

I understand that another pattern might be that I move step 3 to another DB trigger function for messaging. This will introduce some delay as I will need to wait for this trigger function to fire.

My question is, is it safe to add additional logic to the HTTPS function after the response is sent, or can Firebase start clearing / terminating my function already?

+3


source to share


1 answer


firebaser here

While your FCM messaging (in step 3) may often work, it is not reliable. There is no guarantee that the HTTP trigger function will continue to run after the response has been sent.

It is for this reason that the Firebase documentation says:



The HTTP functions are synchronous, so you should send a response as soon as possible and defer the work using the realtime database.

So in your case, the documentation explicitly states that passing a notification to a function initiated by the database.

+2


source







All Articles