Last active
December 28, 2015 04:19
-
-
Save ylansegal/7441737 to your computer and use it in GitHub Desktop.
HardenedWorker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializer/delayed_job.rb | |
Thread.new { Delayed::HardenedWorker.new.start } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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