Emad Armoun
Emad Armoun

Reputation: 2099

How to schedule a firebase function, in limited times

I have a firebase function that should be ran every 1 hour, but only for X times. I scheduled it in this way :

functions.pubsub.schedule('every 1 hour').onRun((context) => {
    let counter = // read last counter value from db
    counter++;
    if(counter === X)
        return;
    // save counter in db

    // my job
}

But this method is not optimal, because the scheduler is always active, even when it's not required. Do you offer a better method for this purpose?

Upvotes: 0

Views: 995

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317322

What you're trying to do isn't supported by scheduled functions. What you'll have to do is schedule future invocations of the function with Cloud Tasks with the specific schedule you want. A complete list of instructions to do this is too long for Stack Overflow, but you can read this blog post to learn how to programmatically schedule future invocations of a Cloud Function.

Upvotes: 1

Related Questions