簡體   English   中英

Firebase Function 間隔 10 分鍾后停止

[英]Firebase Function stops interval after 10 min

我在 firebase 功能上有一個計時器 function。

我的代碼如下

exports.timecontroller = functions.region('europe-west1').firestore.document("DigitalTargets/{digitalTargetID}").onCreate((snap, context) => {
    const id = snap.id
    const date = new Date(snap.data().endDate.toDate())
    var countDownDate = date.getTime();
    var myfunc = setInterval(async function () {
        var now = new Date().getTime();
        var timeleft = countDownDate - now;
        db.collection('DigitalTargets').doc(snap.id).get().then(a => {
            if (!a.data().isClaimed) {
                console.log(timeleft)
                if (timeleft < 0) {
                    db.collection("DigitalTargets").doc(id).update({ isActive: false })
                    clearInterval(myfunc);
                }
            }
            else {
                clearInterval(myfunc);
            }

        })


    }, 1000);
    return true;
})

我的問題是,當我創建文檔時它開始計數。 我可以在日志屏幕上看到。 但 10 分鍾后它停止工作。 不再顯示日志。 過期時間后它不會停用文檔

我需要什么:我將目標放在 map 上,它們有結束時間。 我只想在計時器結束后設置 active false。

firebase 功能有限制嗎? 如果有病,每 5 分鍾檢查一次預定的 function。

聽起來您正在使用創建文檔時啟動的事件驅動 Function。

根據此公共文檔,您可以看到 Even Driven Functions 在 10 分鍾后超時。

另一種方法是讓該事件驅動 function 向另一個 function 發出 http 請求,時間超過 60 分鍾。

從文檔:

The maximum value for timeoutSeconds is 540, or 9 minutes.

https://firebase.google.com/docs/functions/manage-functions

如前所述,您可以使用預定的 function:

exports.myCrontabFunction = functions.pubsub.schedule("every 5 minutes")
    .timeZone("Europe/Berlin")
    .onRun(async (context) => { ... } );

暫無
暫無

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

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