[英]Google cloud function triggered by firebase realtime database events
Apparently some of onCreate/onDelete events our cloud function is triggered by are received more than once!显然,我们的云函数触发的一些 onCreate/onDelete 事件不止一次收到! We've observed them arriving even 3 times a few seconds apart from each other spread between instances of the cloud function.
我们观察到它们在云函数的实例之间传播甚至相隔几秒钟到达 3 次。 Is it a normal behavior or there is something we've been doing wrong?
这是正常行为还是我们做错了什么?
Have a look at the content of this "Firebase Google Group" post , that I paste below.看看我粘贴在下面的这篇“Firebase Google Group” 帖子的内容。 It was written in August 2018 but is still fully valid at the time of writing this "copy/paste answer".
它写于 2018 年 8 月,但在撰写此“复制/粘贴答案”时仍然完全有效。
Cloud Functions typically guarantees that your functions are run "at least once", meaning that it's very possible (but typically rare) that an event may get delivered to your function more than once.
Cloud Functions 通常保证您的函数“至少运行一次”,这意味着一个事件很可能(但通常很少)被多次传递给您的函数。 To deal with this, your functions should be "idempotent", meaning that the receipt of the same event multiple times should result in no further changes to whatever it is you need to update.
为了解决这个问题,你的函数应该是“幂等的”,这意味着多次接收同一个事件应该不会导致你需要更新的任何内容发生进一步的变化。 This can be kind of challenging, but it's one of the properties of serverless systems that needs to be dealt with, if it's problematic for your app.
这可能有点挑战性,但如果它对您的应用程序有问题,它是需要处理的无服务器系统的属性之一。
https://cloud.google.com/functions/docs/bestpractices/tips#write_idempotent_functions
https://cloud.google.com/functions/docs/bestpractices/tips#write_idempotent_functions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.