如何使用 Firebase 运行 cron 作业? [英] How to run cron job with Firebase?

查看:25
本文介绍了如何使用 Firebase 运行 cron 作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Firebase 运行 cron 作业.基本上,我需要运行一个函数,该函数每天在太平洋标准时间凌晨 12:00 进行大量 API 调用并将数据推送到 firebase.有没有办法让我在 Firebase 的服务器端做到这一点?

I am trying to run a cron job with Firebase. Basically I need to run a function that makes a ton of API calls and pushes data to firebase at 12:00am PST every day. Is there a way for me to do this on the server side with Firebase?

我看到有这个模块这里,但我不明白它是如何工作的全部.如果有人有任何想法或知道上述模块如何工作,那就太棒了.

I see that there's this module here, but I don't understand how it works at all. If anyone has any ideas or know how the aforementioned module could work that would be fantastic.

想法.如果我要创建一个显示功能完成时间的数据条目会怎样.基本上检查一下上次调用和完成函数的时间.如果已经过了中午 12 点,则调用该函数并更新该字段,因此直到第二天才会调用它.这是个好主意吗?我不需要该功能恰好在凌晨 12 点发生,我只需要在第一个用户登录时完成即可.

Idea. What if I were to create a data entry that showed the time that the function was completed. Basically check to see that last time the function was called and completed. If it's past 12am then the function is called and the field is updated so it's not called until the next day. Would this be a good idea? I don't need the function to happen at 12am exactly, I just need it to be completed by the time the first user logs in.

推荐答案

在 2019 年 I/O 大会上,它宣布了一项新功能,可以使用 Firebase 函数执行 cronjobs.

At I/O 2019 it was announced a new feature to do cronjobs with firebase functions.

检查一下

export scheduledFunction = functions.pubsub.schedule(‘every 5 minutes’).onRun((context) => {
  console.log(‘This will be run every 5 minutes!’);
});

片段 2

exports.scheduleJobs = functions.pubsub.
schedule("every day 03:00").onRun(async() => {
 // do something
console.log("All done! See you tomorrow morning!");
});

这篇关于如何使用 Firebase 运行 cron 作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆