From 1d8b155bc91ad2ffd6b50f0cd94c4305e4d26181 Mon Sep 17 00:00:00 2001 From: "Ben Sheldon [he/him]" Date: Wed, 4 Aug 2021 18:21:16 -0700 Subject: [PATCH] Ensure CLI can shutdown cleanly with multiple queues and timeout (#319) --- lib/good_job.rb | 6 +++--- spec/lib/good_job/cron_manager_spec.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/good_job.rb b/lib/good_job.rb index c0389f7e8..1521f26bd 100644 --- a/lib/good_job.rb +++ b/lib/good_job.rb @@ -126,13 +126,13 @@ def self.restart(timeout: -1) _shutdown_all(_executables, :restart, timeout: timeout) end - # Sends +#shutdown+ or +#restart+ to executable objects ({GoodJob::Notifier}, {GoodJob::Poller}, {GoodJob::Scheduler}) - # @param executables [Array] Objects to shut down. + # Sends +#shutdown+ or +#restart+ to executable objects ({GoodJob::Notifier}, {GoodJob::Poller}, {GoodJob::Scheduler}, {GoodJob::MultiScheduler}, {GoodJob::CronManager}) + # @param executables [Array] Objects to shut down. # @param method_name [:symbol] Method to call, e.g. +:shutdown+ or +:restart+. # @param timeout [nil,Numeric] # @return [void] def self._shutdown_all(executables, method_name = :shutdown, timeout: -1) - if timeout.positive? + if timeout.is_a?(Numeric) && timeout.positive? executables.each { |executable| executable.send(method_name, timeout: nil) } stop_at = Time.current + timeout diff --git a/spec/lib/good_job/cron_manager_spec.rb b/spec/lib/good_job/cron_manager_spec.rb index dc6a3e602..5abb56361 100644 --- a/spec/lib/good_job/cron_manager_spec.rb +++ b/spec/lib/good_job/cron_manager_spec.rb @@ -44,7 +44,7 @@ cron_manager = described_class.new(schedules, start_on_initialize: true) wait_until(max: 5) do - expect(GoodJob::Job.count).to eq 3 + expect(GoodJob::Job.count).to be > 3 end good_job = GoodJob::Job.first