javascript - 我可以使用函数触发器来调度函数吗?
问题描述
在对集合中的一个文档进行了一些更改后,我需要执行一个 cronjob 函数
例如,当我的用户商店打开时,我需要启动一个 cronjob,它会在用户指定的时间关闭该商店,我当时的想法是这样的
exports.updateUser = functions.firestore
.document('stores/{storeId}')
.onUpdate((change, context) => {
//Logic to get the store close time here, lets say I get close in 4 hours
//Now here I plan to run a cronjob like this
exports.scheduledFunctionCrontab = functions.pubsub.schedule('* 4 * * *')
.timeZone('America/New_York') // Users can choose timezone - default is America/Los_Angeles
.onRun((context) => {
//Close my store in 4 hours
});
});
我可以这样做吗?有没有办法做这样的事情?
谢谢 !
解决方案
您不能从另一个云功能更改计划的云功能的配置。
就您而言,一种解决方案是:
- 在商店文档的特定字段中写下关闭时间;
- 安排一个云函数,它 (a) 例如每分钟运行一次,(b) 检查是否有任何打开的商店文档的关闭时间低于当前运行时间,以及 (c) 是否有任何此类商店文档将其状态修改为关闭。
推荐阅读
- matlab - Matlab:如何在运行完成时设置电子邮件警报?
- abp - ABP 框架 Azure Devops 构建未找到 ABP 库
- android - 在全屏模式下收听状态栏/导航栏可见性?
- php - Mysql JOIN 与 IN 语句 (FIND_IN_SET) *已解决
- python - 使用 pandas 以所需格式读取 JSON 文件
- xmpp - 如何记录 Prosody IM 发送和接收的完整详细的 XMPP 消息
- android - 带有通用接口的 Dagger/DuplicateBindings,即使在使用限定符注释时也是如此
- python - 是 sudo 和脚本中的用户
- c# - 如何在函数中使用任何类型?
- keycloak - 从 postmon 调用 Keycloak 授权服务