本文介绍了如何在有限的时间内安排 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 功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-30 04:26