From ac35eabeeea3a2cfabdc3d41240731df3a994279 Mon Sep 17 00:00:00 2001 From: Gregg Tanzillo Date: Thu, 17 Aug 2017 09:43:02 -0400 Subject: [PATCH] Merge pull request #15529 from jrafanie/give_active_queue_worker_time_to_complete_message Give active queue worker time to complete message (cherry picked from commit 09d2aaec085ab1d58512a36ca1c68f5cc1e3da7c) https://bugzilla.redhat.com/show_bug.cgi?id=1482670 --- app/models/miq_worker.rb | 2 +- lib/tasks/evm_application.rb | 2 +- spec/models/miq_worker_spec.rb | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/app/models/miq_worker.rb b/app/models/miq_worker.rb index bb1e27bfc723..2824f65e185a 100644 --- a/app/models/miq_worker.rb +++ b/app/models/miq_worker.rb @@ -412,7 +412,7 @@ def stopping_for_too_long? # the database, so we can see how long it's been # 'stopping' by checking the last_heartbeat. stopping_timeout = self.class.worker_settings[:stopping_timeout] || 10.minutes - status == MiqWorker::STATUS_STOPPING && last_heartbeat < stopping_timeout.seconds.ago + status == MiqWorker::STATUS_STOPPING && (last_heartbeat + current_timeout.to_i) < stopping_timeout.seconds.ago end def validate_active_messages diff --git a/lib/tasks/evm_application.rb b/lib/tasks/evm_application.rb index 7b449ba28d78..97b9826267b9 100644 --- a/lib/tasks/evm_application.rb +++ b/lib/tasks/evm_application.rb @@ -95,7 +95,7 @@ def self.output_workers_status(servers) s.miq_workers.order(:type).each do |w| data << [w.type, - w.status, + w.status.sub("stopping", "stop pending"), w.id, w.pid, w.sql_spid, diff --git a/spec/models/miq_worker_spec.rb b/spec/models/miq_worker_spec.rb index bf458efb772d..11cf8395f5e6 100644 --- a/spec/models/miq_worker_spec.rb +++ b/spec/models/miq_worker_spec.rb @@ -345,6 +345,20 @@ def check_has_required_role(worker_role_names, expected_result) expect(subject).to be_truthy end + it "true if stopping and last heartbeat is within the queue message timeout of an active message" do + @worker.messages << FactoryGirl.create(:miq_queue, :msg_timeout => 60.minutes) + @worker.update(:status => described_class::STATUS_STOPPING, + :last_heartbeat => 90.minutes.ago) + expect(subject).to be_truthy + end + + it "false if stopping and last heartbeat is older than the queue message timeout of the work item" do + @worker.messages << FactoryGirl.create(:miq_queue, :msg_timeout => 60.minutes, :state => "dequeue") + @worker.update(:status => described_class::STATUS_STOPPING, + :last_heartbeat => 30.minutes.ago) + expect(subject).to be_falsey + end + it "false if stopping and heartbeated recently" do @worker.update(:status => described_class::STATUS_STOPPING, :last_heartbeat => 1.minute.ago)