How to model and store recurring tasks in rails?

calendar, recurring, ruby, ruby-on-rails, scheduling

Solution

I ended up rolling my own solution since I didn't need anything super fancy.

Basically I added a `next_run` datetime and `interval` string column to the db which was one of (day, week, etc). Then setup a cron job to run that looks for any `next_run` dates that have passed. It runs them and then sets `next_run` to some point in the future based on the `interval` column.

Simple but worked for my needs.

Problem

Cron solutions in rails are numerous and pretty good. That's not what I'm struggling with here. Instead, what I'm having trouble with is letting users create their own recurring tasks (like reminders) - specifically how to model and store these in the DB (a good UI for it is non-trivial too - would be awesome if there was code out there for that). Google calendar is a great example here (the UI to add an event, not the entire calendar)...they should be able to do daily at 1pm CST, or mon/wed/fri, or weekly, etc. Whatever cron solution is being used would then need to poll the database to see which reminders needed to be sent at that hour, etc. Anyone seen a good plugin/gem for this in rails? Seems like there would be something out there for it, but I haven't found it yet.

Original source