使用云功能和firestore更新文档后1小时运行一些代码



我的应用程序的用户可以接收消息,我希望他们在创建文档消息后1小时收到推送通知。

这是我的云功能:

export const scheduler = functions.firestore
.document("profile/{uuid}/message/{messageId}")
.onCreate((change, context) => {
//code that will send a notification push in one hour 

return true;
});

我想试试这个(我在那个链接上找到了解决方案:https://firebase.google.com/docs/functions/schedule-functions)但我不知道我是否能取代";每5分钟";一小时后发短信说:

exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
console.log('This will be run every 5 minutes!');
return null;
});

在部署云函数时,必须知道计划云函数运行的时间。您的情况并非如此,因为时间取决于每个单独的文档。

在这种情况下,您可以定期运行计划的云功能,然后检查需要更新的文档,也可以使用云任务创建动态触发器。有关后者的详细示例,请参阅Doug的博客文章How to schedule a Cloud Function to run with Cloud Tasks(to build a Firestore document TTL(。

最新更新