Skip to content

Commit

Permalink
Support GJ v4
Browse files Browse the repository at this point in the history
  • Loading branch information
morgoth committed Jul 16, 2024
1 parent d6b0d40 commit 61fb70c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/hirefire/macro/good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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

0 comments on commit 61fb70c

Please sign in to comment.