From 12ea65f84f618e2641e5efef0069b8488a3a9e80 Mon Sep 17 00:00:00 2001 From: Thorsten Eckel Date: Thu, 5 Jul 2018 16:40:45 +0200 Subject: [PATCH] Ordered failed background jobs by number of entries which also stabilizes test. --- app/controllers/monitoring_controller.rb | 3 ++- test/integration/monitoring_controller_test.rb | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/monitoring_controller.rb b/app/controllers/monitoring_controller.rb index aca2d5b66..b02f7cd3a 100644 --- a/app/controllers/monitoring_controller.rb +++ b/app/controllers/monitoring_controller.rb @@ -96,7 +96,8 @@ curl http://localhost/api/v1/monitoring/health_check?token=XXX end listed_failed_jobs = failed_jobs.select(:handler, :attempts).limit(10) - listed_failed_jobs.group_by(&:name).each_with_index do |(name, jobs), index| + sorted_failed_jobs = listed_failed_jobs.group_by(&:name).sort_by { |_handler, entries| entries.length }.reverse.to_h + sorted_failed_jobs.each_with_index do |(name, jobs), index| attempts = jobs.map(&:attempts).sum diff --git a/test/integration/monitoring_controller_test.rb b/test/integration/monitoring_controller_test.rb index ce648e274..213d03a76 100644 --- a/test/integration/monitoring_controller_test.rb +++ b/test/integration/monitoring_controller_test.rb @@ -632,7 +632,7 @@ class MonitoringControllerTest < ActionDispatch::IntegrationTest assert(result['message']) assert(result['issues']) assert_equal(false, result['healthy']) - assert_equal("13 failing background jobs.;Failed to run background job #1 'BackgroundJobSearchIndex' 2 time(s) with 14 attempt(s).;Failed to run background job #2 'Object' 8 time(s) with 40 attempt(s).", result['message']) + assert_equal("13 failing background jobs.;Failed to run background job #1 'Object' 8 time(s) with 40 attempt(s).;Failed to run background job #2 'BackgroundJobSearchIndex' 2 time(s) with 14 attempt(s).", result['message']) # cleanup Delayed::Job.delete_all