firestore云函数onCreate/onDelete有时会立即触发两次

xak*_*sis 9 firebase google-cloud-functions google-cloud-firestore

我偶尔会在onCreate和onDelete触发器上观察到这种行为. 在此输入图像描述

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

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

这不会一直发生.我错过了什么?

Bob*_*der 9

请参阅Cloud Firestore触发器限制和保证:

目前不保证传递函数调用.随着Cloud Firestore和Cloud Functions集成的改进,我们计划保证"至少一次"交付.但是,在测试期间可能并非总是如此.这也可能导致单个事件的多次调用,因此对于最高质量的函数,确保函数被写为幂等的.

  • 我是唯一一个觉得这种行为完全离谱的人吗?这是否意味着我需要在我不想随机运行两次的每个函数上实现一个 eventID 系统?谷歌怎么能期望我们在生产中使用 Firebase 以这种奇怪的行为?这么无赖,说真的。 (2认同)