From c0cd0d679d7e2acc393f48f173369b5bbebdf453 Mon Sep 17 00:00:00 2001 From: Michael van Rooijen Date: Fri, 26 Jul 2024 16:05:35 +0800 Subject: [PATCH] Exclude running jobs from Good Job measurements --- lib/hirefire/macro/good_job.rb | 4 ++-- test/hirefire/macro/test_good_job.rb | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/hirefire/macro/good_job.rb b/lib/hirefire/macro/good_job.rb index c156aa8..61e33e3 100644 --- a/lib/hirefire/macro/good_job.rb +++ b/lib/hirefire/macro/good_job.rb @@ -25,7 +25,7 @@ def job_queue_latency(*queues) queues = normalize_queues(queues, allow_empty: true) query = ::GoodJob::Execution query = query.where(queue_name: queues) if queues.any? - query = query.where(finished_at: nil) + query = query.where(performed_at: nil) query = query.where(scheduled_at: ..Time.now).or(query.where(scheduled_at: nil)) query = query.order(scheduled_at: :asc, created_at: :asc) @@ -52,7 +52,7 @@ def job_queue_size(*queues) queues = normalize_queues(queues, allow_empty: true) query = ::GoodJob::Execution query = query.where(queue_name: queues) if queues.any? - query = query.where(finished_at: nil) + query = query.where(performed_at: nil) query = query.where(scheduled_at: ..Time.now).or(query.where(scheduled_at: nil)) query.count end diff --git a/test/hirefire/macro/test_good_job.rb b/test/hirefire/macro/test_good_job.rb index 28660f3..f2bd412 100644 --- a/test/hirefire/macro/test_good_job.rb +++ b/test/hirefire/macro/test_good_job.rb @@ -36,9 +36,9 @@ def test_job_queue_latency_with_scheduled_job assert_in_delta 60, HireFire::Macro::GoodJob.job_queue_latency(:mailer), LATENCY_DELTA end - def test_job_queue_latency_finished_jobs + def test_job_queue_latency_with_unfinished_jobs job_id = Timecop.freeze(1.minute.ago) { BasicJob.perform_later.job_id } - GoodJob::Execution.where(active_job_id: job_id).update_all(finished_at: Time.now) + GoodJob::Execution.where(active_job_id: job_id).update_all(performed_at: 1.minute.ago) assert_equal 0, HireFire::Macro::GoodJob.job_queue_latency end @@ -60,9 +60,9 @@ def test_job_queue_size_with_scheduled_jobs assert_equal 1, HireFire::Macro::GoodJob.job_queue_size end - def test_job_queue_size_with_finished_jobs + def test_job_queue_size_with_unfinished_jobs job_id = BasicJob.perform_later.job_id - GoodJob::Execution.where(active_job_id: job_id).update_all(finished_at: Time.now) + GoodJob::Execution.where(active_job_id: job_id).update_all(performed_at: 1.minute.ago) assert_equal 0, HireFire::Macro::GoodJob.job_queue_size end