Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic job scheduling in Rails

I've had a look at a number of scheduling libraries for Rails and I'd like some help choosing one, given that none quite seem to meet my requirements. It's a fairly common use case:

We have a number of reports and we'd like to let users set up when they would want to schedule when and how often a particular report is sent to them by mail. Users need to be able to see a list of the reports they have scheduled and they should be able to cancel or change existing scheduled reports. Scheduled jobs should survive restarts of the server. At the moment I'm not worried about only running jobs on a single node in a cluster of rails servers.

  • Rufus scheduler looks good but I'd have to write code to persist the jobs and restart them when rails restarts.
  • Delayed_job deals with persistence but I can't see how to run jobs on a regular schedule, except possibly in rescheduling a job at a new time when it runs
  • resque with resque-scheduler seems very close but I'd like to avoid having to add redis to our stack and I'd likely end up trying to reimplement some of the UI in rails so that users can add / remove / manage jobs and it would great if it could use the same ActiveRecord backend as the rest of the application.
like image 723
Jamie McCrindle Avatar asked Aug 11 '11 18:08

Jamie McCrindle


2 Answers

I would recommend using Delayed::Job for the actual jobs, as it automatically handles persistence for your users, and you can use the delayed_jobs table for the management (allowing users to modify/delete jobs that they've started).

When it comes to automatically scheduling jobs, you can use the Clockwork gem. It was built by Heroku (If I'm not mistaken), and essentially allows you to emulate/replace cron within your ruby/rails app.

With the two libraries above, you've got all your bases covered.

like image 127
Mike Trpcic Avatar answered Oct 13 '22 20:10

Mike Trpcic


I would decide against resque for exactly the same reasons. Instead we went for delayed-job as well, and indeed, the last thing a job does, is reschedule the job to run again next time.

like image 41
nathanvda Avatar answered Oct 13 '22 19:10

nathanvda