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_spec.rb b/spec/lib/good_job_spec.rb index d331e367a..02a8e1c66 100644 --- a/spec/lib/good_job_spec.rb +++ b/spec/lib/good_job_spec.rb @@ -2,8 +2,9 @@ require 'rails_helper' describe GoodJob do - let(:configuration) { GoodJob::Configuration.new({ queues: 'mice:1', poll_interval: -1 }) } - let!(:scheduler) { GoodJob::Scheduler.from_configuration(configuration) } + let(:configuration) { GoodJob::Configuration.new({ queues: 'mice:1;elephants:1', poll_interval: -1 }) } + let!(:multi_scheduler) { GoodJob::Scheduler.from_configuration(configuration) } + let(:scheduler) { multi_scheduler.schedulers.first } let!(:notifier) { GoodJob::Notifier.new([scheduler, :create_thread]) } describe '.shutdown' do @@ -13,6 +14,13 @@ expect(scheduler.shutdown?).to eq true expect(notifier.shutdown?).to eq true end + + it 'shuts down when there is a timeout set' do + described_class.shutdown(timeout: 5) + + expect(scheduler.shutdown?).to eq true + expect(notifier.shutdown?).to eq true + end end describe '.shutdown?' do @@ -33,6 +41,14 @@ end end + describe '._shutdown_all' do + it 'delegates shutdown methods to multiple instances' do + expect do + described_class._shutdown_all([multi_scheduler, notifier], timeout: 5) + end.to change(described_class, :shutdown?).from(false).to(true) + end + end + describe '.reperform_jobs_on_standard_error' do around do |example| original_retry_on_unhandled_error = described_class.retry_on_unhandled_error