3

In my app users can create an event which can be started immediately or some time later (max 5 days). How can I schedule a Firebase function "StartEvent" at the exact date that the user wants it?

I already tried it with the Node plugin "Node-Schedule" but it seems like Firebase is removing the stored schedule after a certain amount of time.

My other idea would be to set up a cron job on an online service that pings a function every 30 to 60 seconds that checks if an event must be started. But this seems very inefficient to me.

Is there a better way to do this?

AL.
  • 36,815
  • 10
  • 142
  • 281
sunilson
  • 1,449
  • 15
  • 31
  • 1
    If you're having problem getting the solution from [this sample](https://github.com/firebase/functions-samples/tree/master/delete-unused-accounts-cron) or [this blog post](https://firebase.googleblog.com/2017/03/how-to-schedule-cron-jobs-with-cloud.html) to work, post the [minimal code/steps that reproduces the problem](http://stackoverflow.com/help/mcve). – Frank van Puffelen May 16 '17 at 14:25
  • @FrankvanPuffelen I have already had a look at this tutorial, but I can't seem to find a solution where you don't create a recurring task but one at a specific date. Am I missing something? – sunilson May 16 '17 at 14:36
  • 2
    With Cloud Functions, there's currently no way to schedule a one-off task at some specific time or delay. You'll have to arrange for that scheduling to happen on your own, and arrange for a function to be executed on that schedule. That's when the above blog post is trying to get you to do. – Doug Stevenson May 16 '17 at 14:40
  • I've created a feature request for this, please go comment there so that they can see there is interest for this functionality: https://issuetracker.google.com/issues/69577457 – Nico Huysamen Nov 22 '17 at 04:10

1 Answers1

0

if you need a scheduler, I wrote a blog how to create a very simple one: https://mhaligowski.github.io/blog/2017/05/25/scheduled-cloud-function-execution.html.

Basically, you need to set up a very simple instance of AppEngine emitting to PubSub. Your function will be subscribed there. You could probably make it more complex, and create your own scheduler, so that the messages will be emitted to PubSub only when the scheduled time comes.

Hope that helps!

mhaligowski
  • 2,182
  • 20
  • 26