Firestore Cloud函数onCreate/onDelete有时会立即触发两次 [英] firestore cloud functions onCreate/onDelete sometimes immediately triggered twice

查看:23
本文介绍了Firestore Cloud函数onCreate/onDelete有时会立即触发两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶尔通过onCreate和onDelete触发器观察到这种行为.

I have observed this behavior occasionally with both onCreate and onDelete triggers.

两次执行都发生在在Firestore中创建的同一文档中.那里只有一个文档,所以我不知道它如何触发两次处理程序.处理程序本身非常简单:

Both the executions happened for the same document created in firestore. There's only one document there so I don't understand how it could trigger the handler twice. the handler itself is very simple:

module.exports = functions.firestore.document('notes/{noteId}').onCreate((event) => {
  const db = admin.firestore();
  const params = event.params;
  const data = event.data.data();
  // empty
});

这并非一直发生.我想念什么?

this doesn't happen all the time. What am I missing?

推荐答案

请参阅Cloud Firestore触发器

See the Cloud Firestore Triggers Limitations and Guarantees:

当前不保证函数调用的交付.作为 Cloud Firestore和Cloud Functions集成得到改善,我们计划 保证至少一次"交货.但是,这可能并不总是 Beta期间的情况. 这也可能导致多次调用 单个事件,因此要获得最高质量的功能,请确保 这些函数被写为幂等的.

Delivery of function invocations is not currently guaranteed. As the Cloud Firestore and Cloud Functions integration improves, we plan to guarantee "at least once" delivery. However, this may not always be the case during beta. This may also result in multiple invocations for a single event, so for the highest quality functions ensure that the functions are written to be idempotent.

有一个 Firecast视频,其中包含实现幂等的技巧.

There is a Firecast video with tips for implementing idempotence.

还有两篇Google Blog帖子:第一个

Also two Google Blog posts: the first, the second.

这篇关于Firestore Cloud函数onCreate/onDelete有时会立即触发两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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