如何运行后台云功能并安排数据库更改? [英] How to run a background Cloud Function and schedule a change in database?

本文介绍了如何运行后台云功能并安排数据库更改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 React Native 和 Firebase 实时数据库开发应用.我想做这样的事情.

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.

另见:

这篇关于如何运行后台云功能并安排数据库更改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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