Class: Bosh::Director::Worker
Instance Method Summary collapse
-
#initialize(config, index = 0) ⇒ Worker
constructor
A new instance of Worker.
- #prep ⇒ Object
- #queues ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize(config, index = 0) ⇒ Worker
Returns a new instance of Worker.
4 5 6 7 |
# File 'lib/bosh/director/worker.rb', line 4 def initialize(config, index=0) @config = config @index = index end |
Instance Method Details
#prep ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/bosh/director/worker.rb', line 9 def prep Delayed::Worker.logger = @config.worker_logger Bosh::Director::App.new(@config) Delayed::Worker.backend = :sequel Delayed::Worker.destroy_failed_jobs = true Delayed::Worker.sleep_delay = ENV['INTERVAL'] || 1 Delayed::Worker.max_attempts = 0 Delayed::Worker.max_run_time = 31536000 @delayed_job_worker = nil queues = (ENV['QUEUES'] || ENV['QUEUE']).to_s.split(',') queues << @config.director_pool unless @config.director_pool.nil? || (queues - ['urgent']).empty? @delayed_job_worker = Delayed::Worker.new({:queues => queues}) trap('USR1') { @delayed_job_worker.queues = [ 'non_existent_queue' ] } #stop accepting new jobs when USR1 is sent end |
#queues ⇒ Object
49 50 51 |
# File 'lib/bosh/director/worker.rb', line 49 def queues @delayed_job_worker.queues end |
#start ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/bosh/director/worker.rb', line 30 def start @delayed_job_worker.name = "worker_#{@index}" @delayed_job_worker.logger.info("Starting worker #{@delayed_job_worker.name}.") begin @delayed_job_worker_retries ||= 0 @delayed_job_worker.start rescue Exception => e @delayed_job_worker.logger.error("Something goes wrong during worker start. Attempt #{@delayed_job_worker_retries}. Error: #{e.inspect}") while @delayed_job_worker_retries < 10 @delayed_job_worker_retries += 1 sleep 0.5 retry end @delayed_job_worker.logger.error("Max retries reached. Error: #{e.inspect}") raise e end end |