Cloud Functions for Firebase 错误处理

Cloud Functions for Firebase error handling

我想知道当我有链式承诺时编写 node.js 代码的正确方法是什么,如果出现问题我需要更新实时数据库?

代码如下:

export const testErrorHandling = functions.database
      .ref('/workqueue/{pushId}/something').onWrite(event => {

  // Exit when the data is deleted.
  if (!event.data.exists()) {
    return;
  }

  //This is the retry count, give up if more than 5 times have been retried.
  const data = event.data.val()
  if (data.count >= 5) {
    return
  }

  return event.data.ref.root.child(data.fulluri).once('value').then(snapshot => {
    //Process all, if ok, delete the work queue entry
    return event.data.ref.remove()  
  }).catch(exception => {
    console.log('Error!: ' + exception)

    //Log error, increase retry count by one an write to that 
    //location to trigger a retry

    //Is the line below OK?
    //return event.data.ref.child('count').set(data.count + 1)
  })

})

我想这在很多情况下都是常见的要求,但找不到示例,因为所有示例似乎都只是写入 console.error 并完成。 (这在现实世界中是不够的。)

[Firebase Cloud Functions 开发人员] 你的想法很聪明。它会工作很多次,但不会捕获较低级别的问题,例如数据库不可用或您的应用程序超时(尽管可以通过 Promise.race 排队重试来修复)。

我们正在努力为核心产品添加重试。既然你提出了这个问题,我很乐意征求一些客户的意见。作为开发人员,您 need/expect 在重试政策中有哪些特点?您认为什么是合理的默认设置?您希望如何覆盖这些默认设置?