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

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

问题描述

我正在尝试使用Firebase运行Cron作业。基本上,我需要运行一个函数,该函数会在太平洋标准时间每天12:00 AM进行大量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.

推荐答案

在I / O 2019上,它宣布了一项新功能,可以执行具有Firebase功能的cronjob。

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

检查一下

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



代码段2



Snippet 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天全站免登陆