Firebase-queue scheduling system

436 views
Skip to first unread message

Kyle Morgan

unread,
Nov 29, 2016, 6:54:26 PM11/29/16
to Firebase Google Group
I'm new here, so forgive me if I don't follow any predefined format here.

I love using Firebase queues. I'm wondering if there's a way to schedule a task. Instead of processing a task instantly, is there a way to schedule something to happen at a particular time?

So let's say that I have a function that sends out an email to a user. I know I want to send that email at 3pm tomorrow. Should I store the time/data of "3pm" in the task and then just check if it's past that time yet? Or is there a better way to handle it?

I'm sure there's no easy built-in way to do this, but maybe you can help me come up with the best way to implement this in Firebase.

Kato Richardson

unread,
Nov 30, 2016, 10:42:13 AM11/30/16
to Firebase Google Group
Hi Kyle,

I've created a similar layer on top of firebase-queue before, by "queueing" the tasks into a cron folder and then having a little maintenance script that ran on a regular interval and "moved" them into firebase-queue when the correct time interval occurred.

This could be done with data structures or timestamps. With data structures, you would simply create a directory structure similar to a crontab definition: `/yyyy/mm/dd/hh`  and you can query against that every hour to pick up any entries that should be queued to run. In my particular version of this, I also queried `any` on each path as a wildcard.

With timestamps, you would simply construct a query with `orderBy(<timestamp).endAt( firebase.database.ServerValue.TIMESTAMP )`. Anything that has a timestamp less than "now" gets run. If it's a recurring event (indicated by adding something like `isRecurring`) then you simply put it back into the cron by adding the next interval onto the timestamp.

Note that the timestamp approach is simpler to implement by a decent margin, but less robust (consider server crashes/restarts/bugs and edge cases start cropping up).

☼, Kato


--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-talk+unsubscribe@googlegroups.com.
To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/a4c70d63-af3b-4f50-9493-b4d6bf5180a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Kato Richardson | Developer Programs Eng | kato...@google.com | 775-235-8398

Brian Woodward

unread,
Nov 30, 2016, 3:09:51 PM11/30/16
to fireba...@googlegroups.com
Hi Kyle,

Take a look at https://github.com/doowb/firebase-cron which does something similar to what Kato is suggesting with the timestamps. There isn't a way to only schedule a one-time run of a job, but I think I'll try to get that added (or you can remove the job after you're queue has been finished so it won't run again). Since the "nextRun" time is calculated based on the cron pattern, if the server crashes, the jobs will "catch up" when the server is restarted.

I've been using it for a while to run nightly jobs and it's been working for me.

- Brian

Kyle Morgan

unread,
Dec 1, 2016, 11:15:37 PM12/1/16
to Firebase Google Group
Thanks for the suggestion. I was hoping there would be a better way since this is similar to something we tried in the past with MySQL and it was always having serious issues. In order to protect against server crashes, I think I'm going to go with your second suggestion of just having a timestamp and selecting only items that are older than the current time. Thanks!


On Wednesday, November 30, 2016 at 8:42:13 AM UTC-7, Kato Richardson wrote:
Hi Kyle,

I've created a similar layer on top of firebase-queue before, by "queueing" the tasks into a cron folder and then having a little maintenance script that ran on a regular interval and "moved" them into firebase-queue when the correct time interval occurred.

This could be done with data structures or timestamps. With data structures, you would simply create a directory structure similar to a crontab definition: `/yyyy/mm/dd/hh`  and you can query against that every hour to pick up any entries that should be queued to run. In my particular version of this, I also queried `any` on each path as a wildcard.

With timestamps, you would simply construct a query with `orderBy(<timestamp).endAt( firebase.database.ServerValue.TIMESTAMP )`. Anything that has a timestamp less than "now" gets run. If it's a recurring event (indicated by adding something like `isRecurring`) then you simply put it back into the cron by adding the next interval onto the timestamp.

Note that the timestamp approach is simpler to implement by a decent margin, but less robust (consider server crashes/restarts/bugs and edge cases start cropping up).

☼, Kato

On Tue, Nov 29, 2016 at 2:55 PM, Kyle Morgan <kylemo...@gmail.com> wrote:
I'm new here, so forgive me if I don't follow any predefined format here.

I love using Firebase queues. I'm wondering if there's a way to schedule a task. Instead of processing a task instantly, is there a way to schedule something to happen at a particular time?

So let's say that I have a function that sends out an email to a user. I know I want to send that email at 3pm tomorrow. Should I store the time/data of "3pm" in the task and then just check if it's past that time yet? Or is there a better way to handle it?

I'm sure there's no easy built-in way to do this, but maybe you can help me come up with the best way to implement this in Firebase.

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.

To post to this group, send email to fireba...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/a4c70d63-af3b-4f50-9493-b4d6bf5180a1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages