在设定的时间后仅运行一次cron作业 [英] Run a cron job only once after a set time

查看:130
本文介绍了在设定的时间后仅运行一次cron作业的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要运行一次cron作业即可在设置的时间间隔后执行一次特定的云功能,但是有点不确定该怎么做.有什么办法可以通过当前的Google云平台来做到这一点?

I need to run a cron job to perform a specific cloud function after a set interval only once but a bit unsure of how to do it. Is there any way to do this through the current google cloud platform?

推荐答案

在下面的讨论中通过注释进行更新:

Update following our discussion below through comments:

如果您要在创建后2小时内更改Firestore数据库中的文档",可以执行以下操作:

If you want to "change a document in your Firestore database 2 hours after it has been created" you could do as follows:

  1. 在Firestore中创建文档时,请保存创建日期/时间,例如与firebase.firestore.FieldValue.serverTimestamp()
  2. 具有如下所述的定期调用的HTTP Cloud Function(每分钟?每5分钟?),并且首先选择2小时前创建的文档(基于保存的时间戳),然后执行所需的操作对这些文档采取行动.


如果要通过cron作业触发Cloud Function,请注意,通常可以通过HTTP Cloud Function通过cron作业调用Cloud Function URL来实现.


If you want to trigger a Cloud Function through a cron job, note that you would normally do that through an HTTP Cloud Function, calling the Cloud Function URL via the cron job.

您可以使用 cron-job.org 之类的外部服务,也可以使用GCP的App Engine和Cloud Pub/Sub

You can either use an external service like cron-job.org or you can use GCP's App Engine and Cloud Pub/Sub

观看此视频: https://www.youtube.com/watch?v=fEBPAMSk5_8

和此博客文章: https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html

均来自Firebase团队.

both from the Firebase team.

最后请注意,最近GCP发布了新产品 Cloud Scheduler ,该产品可用于调用HTTP Cloud Functions.

Finally note that recently GCP launched a new product, Cloud Scheduler, which can be used to call HTTP Cloud Functions.

这篇关于在设定的时间后仅运行一次cron作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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