How to schedule a firebase function, in limited times

穿精又带淫゛_ 提交于 2021-02-05 10:40:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/60401784/how-to-schedule-a-firebase-function-in-limited-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!