views:

27

answers:

1

Hey there, I'm building an online calendar in Ruby on Rails that needs to send out email notifications whenever a user-created event is about to start/finish (i.e you get a reminder when a meeting is 5 minutes away). What's the best way of figuring out when an event is about to start? Would there be a cron task that checks through all events to find out which ones are starting within a certain threshold (i.e 5 minutes) ? A cron task seems inefficient to me, so I'm wondering what might be a better solution. My events are stored in a mySQL database. There must be a design pattern for this... I'm just at a loss for what to search for.

Any help would be greatly appreciated. Thanks.

+1  A: 

In all likelihood you will probably implement some background queuing mechanism to actually deliver the notifications - at least you certain should be considering this approach.

Assuming this, why not create your delayed notification jobs at event creation time to be delivered when the associated event is starting or finishing. The background queue, which is already waking up periodically to look for work, will pick these up and run them.

However adopting this approach requires you to consider the following (at least):

  • Removing queued notification job if the associated event is removed
  • Amending the notification job if the associated event is amended (say a new time)
  • Ensuring that the polling resolution of the queuing system does not allow notifications to be delivered so late as to be useless.

If you haven't picked a queuing solution for your application you should consider these options

bjg
Thanks! So I'm guessing I'd have to find a queuing system that supports scheduling...
pushmatrix