firebase - Firebase 安排具有多个 crontab 的函数
问题描述
我希望我的函数每天运行一次,但在周末运行两次。如何使用 Firebase 做到这一点?
我的 crontab:
- 0 16 * * *
- 0 22 * * 6,0
据我所知,我唯一的选择是使用不同的 crontab 创建同一函数的另一个实例。有没有更好的办法?
谢谢
解决方案
据我所知,我唯一的选择是使用不同的 crontab 创建同一函数的另一个实例。有没有更好的办法?
是的,这是唯一的解决方案。但是,您可以将“主”代码放在一个函数中,如下所示:
exports.scheduledFunction1 = functions.pubsub.schedule('...').onRun(async (context) => {
try {
await mainFunction();
return null;
} catch (error) {
console.log(error);
return null;
}
});
exports.scheduledFunction2 = functions.pubsub.schedule('...').onRun(async (context) => {
try {
await mainFunction();
return null;
} catch (error) {
console.log(error);
return null;
}
});
async function mainFunction() {
//await ...
}
推荐阅读
- java - Gson:在序列化时仅包含一些具有空值的字段
- python - Python - 错误'序列索引不是带有 __index__ 的 int、切片或实例
- python - VSCode:无法在 Docker 容器上远程调试 python 脚本,因为连接失败
- sql - 无法将表复制到新表中
- sharepoint-online - SharePoint Online - React 现代脚本编辑器 - 安装问题
- r - 数据框中每组的一组选定列的 JSON 汇总列
- android - 捕获错误但继续迭代列表
- python - 有谁知道如何设置具有升级和降级特殊要求的条带特定订阅?
- javascript - 是否可以通过应用程序脚本知道谁是最后修改事件的用户
- java - java - 如何根据用户在java中的输入(扫描仪)计算脚本中的字符串、数字和双精度数?