如何根据火场条件调度功能



我在云函数中有这个条件。条件是如果该值是"0";真";,那么我需要在5分钟后将其设置为false。状态将更新为true,但5分钟后仍保持为true。

if(status == true){
let usersUpdate = {};
usersUpdate[`machines.${on}.status`] = true;
db.collection('customers').doc(doc.id)
.update(usersUpdate);
//wait for 5 minutes
//change status to false
schedule = functions.pubsub.schedule('every 5 minute').onRun((context) => {
console.log('This will be run every 5 minutes!');
let usersUpdate = {};
usersUpdate[`machines.${on}.status`] = false;
db.collection('customers').doc(doc.id)
.update(usersUpdate);
})}

但这行不通。我应该导出pubsub函数吗?

它在Firebase之外,但云任务正是您想要的。超级简单。

https://stackoverflow.com/a/65297948/8698374

最新更新