From 61fb70c0f667273fa885d0892e5f4b9f8113467b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Wn=C4=99trzak?= Date: Tue, 16 Jul 2024 09:47:32 +0200 Subject: [PATCH] Support GJ v4 For context see https://github.com/bensheldon/good_job/discussions/1396#discussioncomment-10050933 --- lib/hirefire/macro/good_job.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/hirefire/macro/good_job.rb b/lib/hirefire/macro/good_job.rb index c156aa8..f24d8de 100644 --- a/lib/hirefire/macro/good_job.rb +++ b/lib/hirefire/macro/good_job.rb @@ -23,9 +23,9 @@ module GoodJob # HireFire::Macro::GoodJob.job_queue_latency(:default, :mailer) def job_queue_latency(*queues) queues = normalize_queues(queues, allow_empty: true) - query = ::GoodJob::Execution + query = base_class 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) @@ -50,12 +50,22 @@ def job_queue_latency(*queues) # HireFire::Macro::GoodJob.job_queue_size(:default, :mailer) def job_queue_size(*queues) queues = normalize_queues(queues, allow_empty: true) - query = ::GoodJob::Execution + query = base_class 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 + + private + + def base_class + version >= Gem::Version.new("4.0.0") ? ::GoodJob::Job : ::GoodJob::Execution + end + + def version + Gem::Version.new(::GoodJob::VERSION) + end end end end