ahs*_*san 87 firebase google-cloud-platform google-cloud-functions
我正在寻找一种方法来为Firebase安排云功能,或者换句话说,在特定时间触发它们.
Fra*_*len 97
目前还没有内置的runat/cron类型触发器.
目前,最好的选择是使用外部服务定期触发HTTP功能.有关详细信息,请参阅functions-samples repo中的此示例.或者使用最近推出的Google Cloud Scheduler通过PubSub或HTTPS触发云功能:
我还强烈建议您阅读Firebase博客上的这篇文章:如何使用Cloudbase和此视频的云功能安排(Cron)工作:使用HTTP触发器和Cron为Firebase定时云功能.
mha*_*ski 11
您可以做的是,启动由cron作业触发的AppEngine实例并发送到PubSub.我特意写了一篇博文,你可能想看看:
https://mhaligowski.github.io/blog/2017/05/25/scheduled-cloud-function-execution.html
首先需要注意的是,根据文档,您的函数将执行的默认时区是标准UCT。如果您想在不同时区触发函数,您可以在此处找到时区列表。
注意!:这是一个有用的网站,可以帮助设置cron 表格式(我发现它非常有用)
以下是您的操作方法:(假设您想使用非洲/约翰内斯堡作为时区)
对于第二代(v2) 函数:
import { onSchedule } from "firebase-functions/v2/scheduler";
export const executeFunction = onSchedule({ schedule: '10 23 * * *', timeZone: 'Africa/Johannesburg' }, () => {
//your function logic goes here
console.log("successfully executed at 23:10 Johannesburg Time!");
});
Run Code Online (Sandbox Code Playgroud)
对于第一代函数:
export const executeFunction = functions.pubsub.schedule("10 23 * * *")
.timeZone('Africa/Johannesburg').onRun(() => {
console.log("successfully executed at 23:10 Johannesburg Time!");
});
Run Code Online (Sandbox Code Playgroud)
如果您想坚持使用默认时区,只需省略时区即可:
第二代
import { onSchedule } from "firebase-functions/v2/scheduler";
export const executeFunction = onSchedule({ schedule: '10 23 * * *' }, () => {
//your function logic goes here
console.log("successfully executed at 23:10 UCT - Coordinated Universal Time!");
});
Run Code Online (Sandbox Code Playgroud)
第一代
export const executeFunction = functions.pubsub.schedule("10 23 * * *")
.onRun(() => {
console.log("successfully executed at 23:10 UCT - Coordinated Universal Time!");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30944 次 |
| 最近记录: |