Skip to content

Commit

Permalink
Exclude running jobs from Good Job measurements
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrooijen committed Jul 26, 2024
1 parent d6b0d40 commit c0cd0d6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/hirefire/macro/good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions test/hirefire/macro/test_good_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

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

Expand Down

0 comments on commit c0cd0d6

Please sign in to comment.