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