2

Is there a simple way to schedule a cloud function to run in the future?

For example I'm making a game that is turn based. If a player doesn't act in time, say a time limit of 10 seconds then the turn should go to the next player.

Peter Warbo
  • 11,136
  • 14
  • 98
  • 193
  • The most common way to do this is to schedule it using a service like cron-job.org. See https://stackoverflow.com/questions/42790735/cloud-functions-for-firebase-trigger-on-time – Frank van Puffelen Jul 20 '18 at 03:20
  • @FrankvanPuffelen as I understand you can schedule jobs at cron-job.org but not dynamically? I need a way to schedule a job dynamically when a player has started his turn and if he's not taken his turn within 10 seconds he should timeout and the turn should go to the next player. – Peter Warbo Jul 20 '18 at 05:33
  • cron-job.org or other solutions linked from my answer are the only way to schedule Cloud Functions at the moment. But I probably wouldn't use Cloud Functions for that type of interval check, somehow the granularity sounds different. There unfortunately is no re-trigger functionality in Cloud Functions. I've built simple priority queue on the realtime database for this in the past, but that requires an active process and thus can't be hosted on Cloud Functions. – Frank van Puffelen Jul 20 '18 at 14:10

1 Answers1

1

You can try a pub/sub method which I think suits better for your needs. See related article here.

Rodrigo Mata
  • 1,779
  • 2
  • 14
  • 23