Skip to content

Commit

Permalink
Merge pull request ManageIQ#15529 from jrafanie/give_active_queue_wor…
Browse files Browse the repository at this point in the history
…ker_time_to_complete_message

Give active queue worker time to complete message
(cherry picked from commit 09d2aae)

https://bugzilla.redhat.com/show_bug.cgi?id=1482670
  • Loading branch information
gtanzillo authored and d-m-u committed Jun 6, 2018
1 parent ffaafb1 commit ac35eab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/miq_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/evm_application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 14 additions & 0 deletions spec/models/miq_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit ac35eab

Please sign in to comment.