-
Notifications
You must be signed in to change notification settings - Fork 330
How To: Rails Background Jobs with ActiveJob
Adam edited this page Mar 13, 2017
·
2 revisions
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 Gemfile.
Set the queueing backend for your app to sneakers
# config/application.rb
module YourApp
class Application < Rails::Application
## ...
config.active_job.queue_adapter = :sneakers
end
endIn your Rakefile, add this:
require 'sneakers/tasks'Which will pull useful tasks for you.
rake sneakers:run
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> )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