What's the Best Background Job Management Library for Rails

What's the best background job management library for Rails?

I've used bj in the past with success. However, I've heard good things about Delayed Job recently. Places like Heroku are offering it.

What's the best background job management library for Rails?

I've used bj in the past with success. However, I've heard good things about Delayed Job recently. Places like Heroku are offering it.

Any background process gems that work with JRuby deployed on Windows?

Solved the problem using the jruby-rack-worker gem, http://github.com/kares/jruby-rack-worker, which let's you use delayed_job to schedule jobs, just provides a different way to kickoff worker processes that is more JRuby/Warbler/Tomcat friendly.

Run a background job every few seconds

Maybe you can try [whenever]: https://github.com/javan/whenever

Then you can add your tasks as bellow:

every 3.hours do
runner "MyModel.some_process"
rake "my:rake:task"
command "/usr/bin/my_great_command"
end

in a schedule.rb file

What's the best way to organize worker processes in Rails?

For me, not wanting to maintain a lot of extra infrastructure is a key priority, so I have used database-backed queues that are run outside of Rails.

In my case, I've used background_job and delayed_job. With background_job, the worker was kept running via cron, so there was no daemon management. With delayed_job, I'm using Heroku and letting them worry about that.

With delayed_job you can pass in as many arguments as your background worker needs to run.

Delayed::Job.enqueue(MyJob.new(param[:one], param[:two], param[:three])

I have not found a good solution to running stuff on a schedule, aside from using script/runner via cron (I prefer to use script/runner over a Rake task because I find it easier to test the code).

I've never had to have a regularly scheduled background process that needed access to a particular Rails request so that hasn't been too much of a problem.

I know there are other, cooler systems with more features but this has worked OK for me, and helps me avoid dealing with setting up a lot of new services to manage.

How do I create a worker daemon which waits for jobs and executes them?

I'd build a queue in a table in the database, and a bit of code that is periodically started by cron, which walks that table, passing requests to Typhoeus and Hydra.

Here's how the author summarizes the gem:

Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.

As users add requests, append them to the table. You'll want fields like:

  • A "processed" field so you can tell which were handled in case the system goes down.
  • A "success" field so you can tell which requests were processed successfully, so you can retry if they failed.
  • A "retry_count" field so you can retry up to "n" times, then flag that URL as unreachable.
  • A "next_scan_time" field that says when the URL should be scanned again so you don't DOS a site by hitting it continuously.

Typhoeus and Hydra are easy to use, and do make it easy to handle multiple requests.

Ruby Equivalent of ASP.NETs Application_Start?

Rails doesn't really have an equivalent. The Whenever RubyGem is a nice abstraction of Cron that lets you use syntax like the example below from within your Rails application:

every 30.seconds do
# Do something interesting...
end

Some resources you may find useful:

  • Cron in Ruby Railscast (covers the Whenever gem)
  • What's the best background job management library for Rails? (Stack Overflow)
  • What is the best way to run asynchronous jobs in a Rails application? (Stack Overflow)


Related Topics



Leave a reply



Submit