Skip to content

Instantly share code, notes, and snippets.

@ylansegal
Last active December 28, 2015 04:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ylansegal/7441737 to your computer and use it in GitHub Desktop.
Save ylansegal/7441737 to your computer and use it in GitHub Desktop.
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