From ecc9b73468af3a43bd19b3aa36d2b119f2ddef9e Mon Sep 17 00:00:00 2001 From: Nick Carboni Date: Tue, 10 Dec 2019 16:27:37 -0500 Subject: [PATCH] Move timeout query to dedicated scope method --- app/models/miq_queue.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/miq_queue.rb b/app/models/miq_queue.rb index 2372ca51b0d4..2bb37a74d3f4 100644 --- a/app/models/miq_queue.rb +++ b/app/models/miq_queue.rb @@ -545,8 +545,12 @@ def check_for_timeout(log_prefix = "MIQ(MiqQueue.check_for_timeout)", grace = 10 end end + def self.candidates_for_timeout + where(:state => STATE_DEQUEUE).where("(select date_part('epoch', updated_on) + msg_timeout) < ?", Time.now.to_i) + end + def self.check_for_timeout - where(:state => STATE_DEQUEUE).where("(select date_part('epoch', updated_on) + msg_timeout) < ?", Time.now.to_i).each(&:check_for_timeout) + candidates_for_timeout.each(&:check_for_timeout) end def finished?