flutter/firebase schedule a function at given time

Viewed 476

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).

3 Answers

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.

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
    });
});
Related