簡體   English   中英

用於Firebase錯誤處理的雲功能

[英]Cloud Functions for Firebase error handling

我想知道當我鏈接promises時編寫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雲功能開發人員]你的想法非常聰明。 它會工作很多次但不會捕獲較低級別的問題,例如數據庫不可用或應用程序超時(盡管可以通過重新排列的Promise.race來修復)。

我們正在努力為核心產品添加重試。 既然你提出了這個問題,我很樂意征求一些客戶的意見。 作為開發人員,您在重試策略中需要/期望哪些功能? 您覺得什么是理智的默認值,您希望如何覆蓋這些默認值?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM