I’m developing an app using React Native and Firebase Realtime database. I want to do something like this.
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
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
How to do this?
Advertisement
Answer
There is no built-in trigger to run after a certain delay that is written in the database.
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.
Also see:
- 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