如何取消预定的Firebase功能? [英] How to cancel a scheduled firebase function?

查看:62
本文介绍了如何取消预定的Firebase功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm developing a NodeJS application, running on Firebase, where I need to schedule some email sendings, for which I intend to use functions.pubsub.schedule.

事实证明,我需要在需要时取消这些作业,并且我想知道一些方法来识别它们以最终取消,并且可以有效地取消它们.

Turns out that I need to cancel those jobs when needed, and I'd like to know some way to identify them for eventual possible cancellation, and some way yo effectively cancel them.

有什么办法吗?提前感谢

Any way to do this? Thanx in advance

推荐答案

使用以下内容创建Cloud Function时:

When you create a Cloud Function with something like this:

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

上面只是建立了一个函数需要运行的时间的表,它没有为每次运行Cloud Function都创建一个单独的任务.

The above merely sets up a table of when the function needs to run, it does not create an individual task for each run of the Cloud Function.

要完全取消Cloud Function,可以从外壳运行以下命令:

To cancel the Cloud Function completely, you can run the following command from a shell:

firebase functions:delete scheduledFunction

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

Note that this will redeploy your Cloud Function the next time you run firebase deploy.

如果您要在特定时间段内跳过发送电子邮件,则应更改 cron计划在该时间间隔内不处于活动状态,或跳过内部您的Cloud Function的代码内的时间间隔.

If you want to instead skip sending emails during a certain time period, you should either change the cron schedule to not be active during that interval, or skip the interval inside your Cloud Function's code.

使用伪代码,如下所示:

In pseudo-code that'd look something like:

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;
});

这篇关于如何取消预定的Firebase功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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