lib/rocket_job/worker_pool.rb in rocketjob-5.1.1 vs lib/rocket_job/worker_pool.rb in rocketjob-5.2.0.beta1

- old
+ new

@@ -1,7 +1,7 @@ -require 'concurrent-ruby' -require 'rocket_job/supervisor/shutdown' +require "concurrent-ruby" +require "rocket_job/supervisor/shutdown" module RocketJob class WorkerPool include SemanticLogger::Loggable @@ -25,21 +25,22 @@ # It spreads out the queue polling over the max_poll_seconds so # that not all workers poll at the same time. # The worker also responds faster than max_poll_seconds when a new job is created. def rebalance(max_workers, stagger_start = false) count = max_workers.to_i - living_count - return 0 unless count > 0 + return 0 unless count.positive? logger.info("#{'Stagger ' if stagger_start}Starting #{count} workers") add_one count -= 1 delay = Config.max_poll_seconds.to_f / max_workers count.times.each do sleep(delay) if stagger_start return -1 if Supervisor.shutdown? + add_one end end # Returns [Integer] number of dead workers removed. @@ -88,15 +89,14 @@ private def add_one workers << Worker.new(id: next_worker_id, server_name: server_name) - rescue StandardError => exc - logger.fatal('Cannot start worker', exc) + rescue StandardError => e + logger.fatal("Cannot start worker", e) end def next_worker_id @worker_id += 1 end - end end