node.js - 如何取消预定的 Firebase 功能?
问题描述
我正在开发一个 NodeJS 应用程序,在 Firebase 上运行,我需要安排一些电子邮件发送,我打算为此使用 functions.pubsub.schedule。
事实证明,我需要在需要时取消这些工作,并且我想知道一些方法来识别它们以最终可能取消,并且以某种方式有效地取消它们。
有什么办法可以做到这一点?提前感谢
解决方案
当您使用以下内容创建云函数时:
exports.scheduledFunction = functions.pubsub.schedule('every 5 minutes').onRun((context) => {
console.log('This will be run every 5 minutes!');
return null;
});
以上只是设置了函数需要运行的时间表,并没有为 Cloud Function 的每次运行创建单独的任务。
要完全取消 Cloud Function,您可以从 shell 运行以下命令:
firebase functions:delete scheduledFunction
请注意,这将在您下次运行时重新部署您的 Cloud Function 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;
});
推荐阅读
- html - 为什么我的 flex-row 不能在我的内部 div 上工作
- java - 将所有方法声明为静态以节省内存是否有意义?
- python - 如何在python中创建文件夹的Windows快捷方式
- python - 您如何为带有列表的字典列表绘制条形图?
- python - DecisionTreeClassifier 的 class_weight 属性对混淆矩阵没有影响,召回
- android - 房间数据库更新后 LiveData 观察不起作用
- javascript - Chrome 扩展 - 仅将 Web 元素中的文本保存为变量
- javascript - 来自子级的反应更新状态破坏了同一级别的组件
- javascript - 如何使用 Joi 验证引用的模式?
- java - 尝试使用变量进行简单计算时,变量可能尚未初始化