如何在有限的时间内安排Firebase功能 [英] How to schedule a firebase function, in limited times

查看:63
本文介绍了如何在有限的时间内安排Firebase功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个firebase函数,该函数应该每1小时运行一次,但只能运行X次.我是这样安排的:

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?

推荐答案

计划功能不支持您尝试执行的操作.您需要做的是使用您指定的时间表通过 Cloud Tasks 安排该函数的将来调用想.这样做的完整说明列表对于Stack Overflow来说太长了,但是您可以

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.

这篇关于如何在有限的时间内安排Firebase功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆