Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best current rails background task method?

I am trying to find out the best way to run scripts in the background. I have been looking around and found plenty of options, but many/most seem to have become inactive in the past few years. Let me describe my needs.

The rails app is basically a front-end to configure when and how these scripts will be run. The scripts run and generate reports and send email alerts. So the user must be able to configure the start times and how often these scripts will run dynamically. The scripts themselves should have access to the rails environment in order to save the resulting reports in the DB.

Just trying to figure out the best method from the myriad of options.

like image 964
Eric Seifert Avatar asked Mar 13 '12 22:03

Eric Seifert


2 Answers

I think you're looking for a background job queuing system.

For that, you're either looking for resque or delayed_job. Both support scheduling tasks at some point in the future -- delayed_job does this natively, whereas resque has a plugin for it called resque_scheduler.

You would enqueue jobs in the background with parameters that you specify, and then at the time you selected they'll be executed. You can set jobs to recur indefinitely or a fixed number of times (at least with resque-scheduler, not sure about delayed_job).

delayed_job is easier to set up since it saves everything in the database. resque is more robust but requires you to have redis in your stack -- but if you do already it's pretty much the ideal solution for your problem.

like image 96
Veraticus Avatar answered Nov 16 '22 00:11

Veraticus


I recently learned about Sidekiq, and I think it is really great.

There's also a RailsCast about it - Sidekiq.

like image 33
TWA Avatar answered Nov 16 '22 00:11

TWA