Firebase HTTP功能终止 [英] firebase HTTP function termination

查看:80
本文介绍了Firebase HTTP功能终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发送响应后,可以在Firebase HTTPS函数中添加其他逻辑吗?

Is it OK practice to put additional logic into a Firebase HTTPS function, after the response was sent?

我有发生这种情况的函数:

I have functions where this is happening:

  1. 写入Firebase数据库
  2. 写入完成后,我会发回响应(这是res.status(200 / 500).send()所在的位置 叫)
  3. 我在数据库中查找一些FCM令牌并发送推送消息(从请求者的角度来看这是否成功无关紧要)
  1. write to the Firebase DB
  2. once the write is done, I send back the response (this is where res.status(200 / 500).send() is called)
  3. I look up some FCM tokens in the DB and send a push message (it does not matter from a requester perspective if this is successful or not)

我知道另一个模式可能是我将第3步移到另一个DB触发器函数来执行消息传递.那样会带来一些延迟,因为我需要等待该DB触发函数触发.

I understand that another pattern could be that I move step 3 to another DB trigger function to do the messaging. That would introduce some delay as I'd need to wait for that DB trigger function to fire.

我的问题是:是否可以安全地在HTTPS函数之后添加其他逻辑到HTTPS函数 发送响应,或者Firebase可能已经开始清理/终止我的功能了?

My question is: is it safe to put additional logic to a HTTPS function after the response is sent, or Firebase may start to cleanup / terminate my function already?

推荐答案

firebaser此处

虽然发送FCM消息(在步骤3中)可能经常起作用,但这并不可靠.无法保证发送响应后,HTTP触发的功能将继续运行.

While your sending of FCM messages (in step 3) may frequently work, it is not reliable. There is no guarantee that the HTTP-triggered function will continue running after a response has been sent.

正是出于这个原因, Firebase文档说:

Precisely for this reason the Firebase documentation says:

HTTP函数是同步的,因此您应该尽快发送响应并推迟使用Cloud Firestore的工作.

HTTP functions are synchronous, so you should send a response as quickly as possible and defer work using Cloud Firestore.

因此,在您的情况下,文档明确表示将通知的发送放入数据库触发的函数中.

So in your case, the documentation explicitly says to put the sending of the notification into a database-triggered function.

这篇关于Firebase HTTP功能终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆