如何运行后台云功能并计划数据库更改? [英] How to run a background Cloud Function and schedule a change in database?
问题描述
我正在使用React Native和Firebase Realtime数据库开发一个应用程序.我想做这样的事情.
I'm developing an app using React Native and Firebase Realtime database. I want to do something like this.
我从应用程序中设置了持续时间,然后按下一个按钮.然后,它将数据写入Firebase.假设我将持续时间设置为 1000000000 ms
,然后按下按钮.然后,数据库如下所示:
From the app, I set a time duration and press a button. Then, it writes data to the Firebase. Assume that I set the time duration to 1000000000 ms
and press the button. Then, the database looks like this:
schedules
|
|--schedule1
|
|--status: "Running"
|--durationInMS: 1000000000
我想运行一个后台功能,在 1000000000 ms
之后将上述状态更改为"TimeOver".即使关闭应用程序,该功能也应在后台运行:
I want to run a background function that changes the above status to "TimeOver" after 1000000000 ms
. This function should be run in the background even if the app is closed:
schedules
|
|--schedule1
|
|--status: "TimeOver"
|--durationInMS: 1000000000
该怎么做?
推荐答案
在数据库中写入一定的延迟后,没有内置触发器可以运行.
There is no built-in trigger to run after a certain delay that is written in the database.
但是您可以使用 Cloud Scheduler 构建自己的调度程序,也可以创建定期运行的<一个href ="https://firebase.google.com/docs/functions/schedule-functions" rel ="nofollow noreferrer">预定功能,然后检查数据库中已过期的预定.
But you can either build your own scheduler using Cloud Scheduler, or create a regularly running scheduled function that then checks for expired schedules in your database.
另请参阅:
- Firebase的云功能是否按时触发?
- 如何在firebase中以编程方式创建cron作业
- 按需n秒后执行云功能
- Firebase函数,在15分钟后运行用户不活动状态
- 计划的云功能Firebase
- 博客文章 Firebase中的动态计划后台作业
- Cloud Functions for Firebase trigger on time?
- How to create cron jobs in firebase programmatically
- Executing cloud functions after n seconds on demand
- Firebase Functions, run after 15 minutes of user inactivity
- How can we get Firestore to trigger an event when a document's Date/Time field matches current time?
- Scheduled Cloud Functions Firebase
- the blog post How to schedule a Cloud Function to run in the future with Cloud Tasks (to build a Firestore document TTL)
- the article Dynamic Scheduled Background Jobs in Firebase
这篇关于如何运行后台云功能并计划数据库更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!