'flutter/firebase schedule a function at given time
I want to schedule the cloud function at a specific time and that time will be in firestore document.I want that when i add data inside firestore, a cloud function will trigger and get data from that latest added document and will fetch date and time from that document data and then schedule a cloud function at that specific time to perform a specific task (update status in firestore).
Solution 1:[1]
For the time scheduling check this official documentation out: https://firebase.google.com/docs/functions/schedule-functions
If you want to execute code on database changes check the triggers out: https://firebase.google.com/docs/functions/database-events
You will need something like onUpdate(). Depends on your needs.
You can store files in the firebase storage. Check out the official documentation for a code example. https://firebase.google.com/docs/storage/web/list-files
In case you want to read data from the firebase in your Flutter app, you can implement the flutter-firebase packages. Here you can find the instructions for all firebase packages: https://firebase.flutter.dev/
Stack Overflow is for asking questions. Your Question sounds more like you expecting that someone will give you the whole code, so you don't have to do any research about that. If that's not the case, sorry for the misunderstanding.
Solution 2:[2]
Cloud Functions trigger for Firestore writes. There is nothing built in to trigger them at a time that is specific in the document that is written.
But you can build that yourself using Cloud Tasks, as Doug shows in this excellent blog post: How to schedule a Cloud Function to run in the future with Cloud Tasks (to build a Firestore document TTL)
Solution 3:[3]
I used the node-schedule package inside the Firebase Cloud Functions, after which I was able to schedule tasks at dynamic times from FireStore.
Here is sample code:
exports.scheduleMessage=functions.firestore.document('users/{userID}/pending/{messageID}').onCreate(async (snapshot,context) =>{
schedule.scheduleJob(messageId,`myDate.getUTCMinutes()
myDate.getUTCHours() * * *`, async () =>{
// your logic inside
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mfrischbutter |
| Solution 2 | Frank van Puffelen |
| Solution 3 | Jeremy Caney |
