From 212b3c0fbed0a036b1a29b5baff516fbe71d2007 Mon Sep 17 00:00:00 2001 From: Hussein El Motayam Date: Mon, 15 Jan 2018 03:36:03 +0200 Subject: [PATCH 1/2] Extra disappeared check to avoid false-positives This should fix https://github.com/twonegatives/attentive_sidekiq/issues/7 --- lib/attentive_sidekiq/manager.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/attentive_sidekiq/manager.rb b/lib/attentive_sidekiq/manager.rb index b27f055..15336ee 100644 --- a/lib/attentive_sidekiq/manager.rb +++ b/lib/attentive_sidekiq/manager.rb @@ -18,6 +18,15 @@ def update_disappeared_jobs suspicious = AttentiveSidekiq::Suspicious.jobs active_ids = AttentiveSidekiq::Active.job_ids those_lost = suspicious.delete_if{|i| active_ids.include?(i["jid"])} + + # Sidekiq might have been too fast finishing up a job that appeared in the suspicious list + # but didn't make it to the active list, so that's a false-positive. + # We need to get the new suspicious list again, and remove any lost jobs that are no longer there. + # Those jobs that appeared in the first suspicious list, but not the second one were simply finished + # quickly by Sidekiq before showing up as active by a worker. + suspicious = AttentiveSidekiq::Suspicious.jobs + those_lost.delete_if{|i| !suspicious.include?(i["jid"])} + those_lost.each do |job| Disappeared.add(job) Suspicious.remove(job['jid']) From 6a27199959e0c5ae3418a973d08c86bba1766aeb Mon Sep 17 00:00:00 2001 From: Hussein El Motayam Date: Mon, 15 Jan 2018 04:21:58 +0200 Subject: [PATCH 2/2] Fixed the hash JID lookup --- lib/attentive_sidekiq/manager.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/attentive_sidekiq/manager.rb b/lib/attentive_sidekiq/manager.rb index 15336ee..85d1c34 100644 --- a/lib/attentive_sidekiq/manager.rb +++ b/lib/attentive_sidekiq/manager.rb @@ -25,7 +25,7 @@ def update_disappeared_jobs # Those jobs that appeared in the first suspicious list, but not the second one were simply finished # quickly by Sidekiq before showing up as active by a worker. suspicious = AttentiveSidekiq::Suspicious.jobs - those_lost.delete_if{|i| !suspicious.include?(i["jid"])} + those_lost.delete_if{|i| !suspicious.any?{|j| i['jid'] == j['jid']} } those_lost.each do |job| Disappeared.add(job)