How to simulate and store repetitive tasks in rails?

Cron's solutions on rails are plentiful and pretty good. This is not what I'm fighting right now.

Instead, I have problems with allowing users to create their own repetitive tasks (for example, reminders) - in particular, how to model and store them in the database (a good user interface for it is not trivial) - it will be awesome if there was code for this) . The Google calendar is a great example here (user interface to add an event, not the entire calendar) ... they should be able to do daily at 13:00 CST, or mon / wed / free, or weekly, etc. Regardless of which cron solution it will then be necessary to poll the database to see which reminders need to be sent at this hour, etc.

Has anyone seen a good plug / gem for this in rails? There seems to be something to it, but I haven't found it yet.

Thanks!

+5
source share
4 answers

In the end, I finished my own decision, since I did not need anything unusual.

I basically added a next_rundatetime row column intervalto db too, which was one of (day, week, etc.). Then configure the cron job to run, which looks for any past dates next_run. It launches them, and then installs next_runat some point in the future based on the column interval.

Simple but worked for my needs.

+5
source

We are currently thinking of using such a plugin to store repetitions in the table http://github.com/fnando/recurrence/tree/master

, datetime, . cron ...

get all reminder whose "next_send" date has passed
for each reminder
  send it
  update the "next_send" field using the recurrence object
end

, .

+1

, (RFC, ) . Ruby iical, ri_cal.

+1

, , , :

class AllowReoccuringTasks < ActiveRecord::Migration  
    def self.up  
        add_column :tasks, :reoccuring, :boolean  
        add_column :tasks, :period, :integer  
    end
end

1 ( ), 7 ( ) 14 ( ).

If you want to support other types of schedules, for example, every month, weekdays, weekends, etc., you can instead add a column called “schedule” and use constants to represent different types of schedules. You can also use the enum plugin .

0
source

All Articles