-->

Cloud Functions for Firebase based timer

2020-07-24 05:00发布

问题:

So I know that Cloud Functions for Firebase don't natively support cron jobs, and one have to depend on an external source to trigger an HTTP cloud function. But I don't think this will work in my case.

I have an app in which users can create competitions that end in 24 hours, thus each time a competition is created, I need to set up a timer that triggers one time after 24 hours.

Do you guys have any idea on how this problem can be approached?

回答1:

At this moment the solution that the Firebase guys are providing for solving the cron issue is to use Google App Engine to deploy a server and trigger the functions via Pub/Sub hooks. Here you can find the tutorial. Basically you have to:

  1. Create a Cloud Function that responds to a PubSub hook.
  2. Deploy an App Engine that will publish an event depending on the cron setup you set.

If you don't want to setup an App Engine you can use an external resource like cron-job.org that can call your HTTP Cloud Function.