Jos*_*ito 0 schedule node.js firebase google-cloud-functions
我正在开发一个在 Firebase 上运行的 NodeJS 应用程序,我需要安排一些电子邮件发送,为此我打算使用functions.pubsub.schedule。
事实证明,我需要在需要时取消这些工作,我想知道一些方法来识别它们以最终可能取消,以及一些有效地取消它们的方法。
有办法做到这一点吗?提前感谢
当您使用如下内容创建云函数时:
exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
console.log('This will be run every 5 minutes!');
return null;
});
Run Code Online (Sandbox Code Playgroud)
上面只是设置了函数需要运行的时间的表格,并没有为云函数的每次运行创建单独的任务。
要完全取消云函数,您可以从 shell 运行以下命令:
firebase functions:delete scheduledFunction
Run Code Online (Sandbox Code Playgroud)
请注意,这将在您下次运行时重新部署您的云功能firebase deploy。
如果您想在特定时间段内跳过发送电子邮件,您应该将cron 计划更改为在该时间间隔内不处于活动状态,或者跳过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;
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1865 次 |
| 最近记录: |