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

查看:14
本文介绍了firestore 云函数 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 集成得到改进,我们计划保证至少一次"交付.然而,这可能并不总是测试期间的情况.这也可能导致多次调用对于单个事件,因此对于最高质量的功能,请确保函数被编写为幂等的.

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 博客文章:第一个第二个.

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

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

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