Using Delayed-Job With Elasticsearch As a Backend

Get Started

$ rails new delayed_job_rails_project --skip-active-record
# Gemfile
gem 'delayed_job_es'
$ bundle install
# app/jobs/background_job.rbclass BackgroundJob < ActiveJob::Base

queue_as :default

## Specify the queue adapter as delayed_job_es
self.queue_adapter = :delayed_job

self.logger = Logger.new(nil) if Rails.env.test?
rescue_from(StandardError) do |exception|
puts exception.message
puts exception.backtrace.join("\n")
end

def perform(args)
puts "got the job"
puts args
end

end
# in the rails console, (you only need to do this once)
DelayedJob::Backend::Es::Job.create_indices
# on the console, start the job daemon
$ bundle exec rake jobs:work
# run this from the rails console, or from within your code.
BackgroundJob.perform_later({"hello" => "world"})

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store