-
Notifications
You must be signed in to change notification settings - Fork 332
How To: Rails Background Jobs
Using Sneakers is simple with Rails too. You can get along fine with what you've seen so far, however since we're using Rails, we can adapt to be even more productive by hooking up some conventions.
Hopefully we'll create a sneakers-rails
gem that sets this up for you, but until then here's how to set up manually.
As always, add sneakers
to your Gemfile
.
In your Rakefile
, add this:
require 'sneakers/tasks'
Which will pull useful tasks for you.
rake sneakers:run # Start work (set $WORKERS=Klass1,Klass2)
Next, let's give you a place to configure global parameters for Sneakers; often this is all you'll do, or better, you won't need it and just use the default configuration.
Set up an initializer file, named after the sneakers
gem.
# config/initializers/sneakers.rb
require 'sneakers'
Sneakers.configure( <your connection params, etc> )
If you're used to declaring workers on ENV, you need to export the worker classes you want to run, and invoke the Sneakers rake task:
WORKERS=WebScraper rake sneakers:run
That's all folks. Hopefully we'll some time implement a sneakers-rails
gem that does this setup for you. We're accepting pull requests :)