Skip to content

Instantly share code, notes, and snippets.

@ylansegal
Last active Dec 28, 2015
Embed
What would you like to do?
HardenedWorker
# config/initializer/delayed_job.rb
Thread.new { Delayed::HardenedWorker.new.start }
require 'delayed/j_ruby_worker'
module Delayed
class HardenedWorker
attr_reader :options
def initialize(options = {})
@options = options
end
def worker
Delayed::JRubyWorker.new(options)
end
def start_once
begin
worker.start
rescue Exception => ex
Rails.logger.error "Delayed::Worker failed with #{ex.class.name}: #{ex.message}"
ensure
sleep 1
end
end
def start
loop do
start_once
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment