计划的云功能Firebase [英] Scheduled Cloud Functions Firebase

查看:57
本文介绍了计划的云功能Firebase的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试基于Firestore数据库中的 DateTime 对象字段计划要运行的功能.

I am trying to schedule a function to run based on DateTime object field in my Firestore database.

例如,我在数据库中有一个事件集合,每个事件都有一个DateTime字段(开始时间)作为事件开始的时间.该事件还具有订阅该事件的用户列表.

Example, I have a collection of events in the Database and each event has a DateTime field (Start time) for the start of the event. The event also has a list of users that are subscribed to the event.

是否可以使用Cloud Functions通知订阅的用户该事件将在事件开始时或事件开始前5或10分钟开始?

Is there a way to use Cloud Functions to notify the subscribed users that the event is about to start at the start time of the event or 5 or 10 mins before the event starts?

我目前正在使用Cloud Functions进行通知并可以正常工作,但这是基于对数据库特定部分的写入,而不是时间事件.

I am currently using Cloud Functions for notification and its working fine but that is based writes to specific portions of the database, not time event.

谢谢.

推荐答案

使用计划的Cloud Function进行此类工作的唯一方法是安排其定期运行(最常每1分钟运行一次),并且查询符合您要在当前功能正在运行时发送通知的条件的文档.这意味着您应该在距当前时间不远的5-10分钟内查找文档.

The only way to do this with a scheduled Cloud Function for this sort of work is to schedule it run periodically (every 1 minute is the most often), and query for documents that meet the criteria for when you want to send the notification at the moment that the function is currently running. This means you should be looking for documents where the time is in the 5-10 minute near future from the current time.

您不能使用计划的云功能来延迟某些工作,以防稍后发生.但您可以为此与云任务集成.

You can't use scheduled Cloud Functions to delay some work to happen later. But you can integrate with Cloud Tasks for that.

这篇关于计划的云功能Firebase的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆