Run a cron job only once after a set time

与世无争的帅哥 提交于 2020-06-26 07:44:12

问题


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?


回答1:


Update following our discussion below through comments:

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

  1. When creating the document in Firestore, save the date/time of creation, e.g. with firebase.firestore.FieldValue.serverTimestamp()
  2. Have an HTTP Cloud Function that you call regularly as explained below (every minutes? every 5 minutes?) and that, first, selects the documents that were created 2 hours ago (based on the saved timestamp) and then do the desired action on these docs.

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.

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

See this video: https://www.youtube.com/watch?v=fEBPAMSk5_8

and this Blog post: https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html

both from the Firebase team.


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



来源:https://stackoverflow.com/questions/55548517/run-a-cron-job-only-once-after-a-set-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!