【问题标题】:How to cancel a scheduled firebase function?如何取消预定的 Firebase 功能?
【发布时间】:2020-03-25 18:00:46
【问题描述】:

我正在开发一个 NodeJS 应用程序,在 Firebase 上运行,我需要安排一些电子邮件发送,我打算为此使用 functions.pubsub.schedule。

事实证明,我需要在需要时取消这些工作,我想知道一些方法来识别它们以便最终可能取消,以及一些有效地取消它们的方法。

有什么办法吗? 提前感谢

【问题讨论】:

    标签: node.js firebase google-cloud-functions schedule


    【解决方案1】:

    当您使用以下内容创建云函数时:

    exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
      console.log('This will be run every 5 minutes!');
      return null;
    });
    

    上面只是建立了一个函数需要运行的时间表,并没有为云函数的每次运行创建一个单独的任务。


    要完全取消云功能,您可以在 shell 中运行以下命令:

    firebase functions:delete scheduledFunction
    

    请注意,这将在您下次运行 firebase deploy 时重新部署您的 Cloud Function。


    如果您想在特定时间段内跳过发送电子邮件,则应将 cron schedule 更改为在该时间间隔内不活动,或跳过 inside Cloud Function 代码的时间间隔。

    在看起来像这样的伪代码中:

    exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
      console.log('This will be run every 5 minutes!');
      if (new Date().getHours() !== 2) {
        console.log('This will be run every 5 minutes, except between 2 and three AM!');
        ...
      }
      return null;
    });
    

    【讨论】:

      猜你喜欢
      • 2020-05-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多