Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
How To: Rails Background Jobs with ActiveJob
Rails' Active Job is a shared interface for working with asynchronous job queues. Among others, it has a queue adapter for Sneakers and it's very easy to set up.
As always, add
sneakers to your
Set the queueing backend for your app to
# config/application.rb module YourApp class Application < Rails::Application ## ... config.active_job.queue_adapter = :sneakers end end
Rakefile, add this:
Which will pull useful tasks for you.
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
# config/initializers/sneakers.rb require 'sneakers' Sneakers.configure( <your connection params, etc> )
Generate a new job with
rails generate job <name>, edit it then invoke the Sneakers rake task with:
WORKERS=ActiveJob::QueueAdapters::SneakersAdapter::JobWrapper rake sneakers:run