我在 firebase 功能上有一個計時器功能。
我的代碼如下
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分鐘后它停止作業。不再顯示日志。過期時間后,它不會停用檔案
我需要什么:我在地圖上放置目標并且它們有結束時間。我只想在計時器完成后將活動設定為 false。
firebase 功能有什么限制嗎?如果有計劃的功能每 5 分鐘檢查一次。
uj5u.com熱心網友回復:
從檔案:
The maximum value for timeoutSeconds is 540, or 9 minutes.
https://firebase.google.com/docs/functions/manage-functions
如前所述,您可以使用預定功能:
exports.myCrontabFunction = functions.pubsub.schedule("every 5 minutes")
.timeZone("Europe/Berlin")
.onRun(async (context) => { ... } );
uj5u.com熱心網友回復:
聽起來您正在使用在創建檔案時啟動的事件驅動函式。
根據此公開檔案,您可以看到 Even Driven Functions 在 10 分鐘后超時。
另一種方法可能是讓該事件驅動函式向另一個函式發出 http 請求,時間超過 60 分鐘。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/498231.html
