如何取消预定的 firebase 功能?
How to cancel a scheduled firebase function?
我正在 Firebase 上开发一个 NodeJS 应用程序 运行,我需要在其中安排一些电子邮件发送,我打算为此使用 functions.pubsub.schedule。
事实证明我需要在需要时取消这些工作,我想知道一些方法来识别它们以便最终可能取消,以及一些有效取消它们的方法。
有什么办法吗?
提前致谢
当您使用如下内容创建 Cloud Functions 时:
exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
console.log('This will be run every 5 minutes!');
return null;
});
上面只是设置了一个table的函数需要运行的时候,并没有为Cloud Function的每个运行创建一个单独的任务。
要完全取消 Cloud Function,您可以 运行 来自 shell 的以下命令:
firebase functions:delete scheduledFunction
请注意,这将在您下次 运行 firebase deploy
时重新部署您的 Cloud Function。
如果您想在特定时间段内跳过发送电子邮件,您应该将 cron schedule 更改为在该时间段内不处于活动状态,或者跳过时间间隔 inside 您的 Cloud Functions 代码。
在看起来像这样的伪代码中:
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 上开发一个 NodeJS 应用程序 运行,我需要在其中安排一些电子邮件发送,我打算为此使用 functions.pubsub.schedule。
事实证明我需要在需要时取消这些工作,我想知道一些方法来识别它们以便最终可能取消,以及一些有效取消它们的方法。
有什么办法吗? 提前致谢
当您使用如下内容创建 Cloud Functions 时:
exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
console.log('This will be run every 5 minutes!');
return null;
});
上面只是设置了一个table的函数需要运行的时候,并没有为Cloud Function的每个运行创建一个单独的任务。
要完全取消 Cloud Function,您可以 运行 来自 shell 的以下命令:
firebase functions:delete scheduledFunction
请注意,这将在您下次 运行 firebase deploy
时重新部署您的 Cloud Function。
如果您想在特定时间段内跳过发送电子邮件,您应该将 cron schedule 更改为在该时间段内不处于活动状态,或者跳过时间间隔 inside 您的 Cloud Functions 代码。
在看起来像这样的伪代码中:
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;
});