Module: HireFire::Macro::GoodJob

Extended by:
Deprecated::GoodJob, GoodJob, Helpers::GoodJob, Utility
Included in:
GoodJob
Defined in:
lib/hirefire/macro/good_job.rb

Instance Method Summary collapse

Methods included from Helpers::GoodJob

error_event_supported?, good_job_class, included

Methods included from Deprecated::GoodJob

queue

Instance Method Details

#job_queue_latency(*queues) ⇒ Float

Calculates the maximum job queue latency using GoodJob. If no queues are specified, it measures latency across all available queues.

Examples:

Calculate latency across all queues

HireFire::Macro::GoodJob.job_queue_latency

Calculate latency for the “default” queue

HireFire::Macro::GoodJob.job_queue_latency(:default)

Calculate latency across “default” and “mailer” queues

HireFire::Macro::GoodJob.job_queue_latency(:default, :mailer)

Parameters:

  • queues (Array<String, Symbol>)

    (optional) Names of the queues for latency measurement. If not provided, latency is measured across all queues.

Returns:

  • (Float)

    Maximum job queue latency in seconds.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/hirefire/macro/good_job.rb', line 26

def job_queue_latency(*queues)
  queues = normalize_queues(queues, allow_empty: true)
  query = good_job_class
  query = query.where(queue_name: queues) if queues.any?
  query = query.where(performed_at: nil)
  query = query.where.not(error_event: discarded_enum).or(query.where(error_event: nil)) if error_event_supported?
  query = query.where(scheduled_at: ..Time.now).or(query.where(scheduled_at: nil))
  query = query.order(scheduled_at: :asc, created_at: :asc)

  if (job = query.first)
    Time.now - (job.scheduled_at || job.created_at)
  else
    0.0
  end
end

#job_queue_size(*queues) ⇒ Integer

Calculates the total job queue size using GoodJob. If no queues are specified, it measures size across all available queues.

Examples:

Calculate size across all queues

HireFire::Macro::GoodJob.job_queue_size

Calculate size for the “default” queue

HireFire::Macro::GoodJob.job_queue_size(:default)

Calculate size across “default” and “mailer” queues

HireFire::Macro::GoodJob.job_queue_size(:default, :mailer)

Parameters:

  • queues (Array<String, Symbol>)

    (optional) Names of the queues for size measurement. If not provided, size is measured across all queues.

Returns:

  • (Integer)

    Total job queue size.



54
55
56
57
58
59
60
61
62
# File 'lib/hirefire/macro/good_job.rb', line 54

def job_queue_size(*queues)
  queues = normalize_queues(queues, allow_empty: true)
  query = good_job_class
  query = query.where(queue_name: queues) if queues.any?
  query = query.where(performed_at: nil)
  query = query.where.not(error_event: discarded_enum).or(query.where(error_event: nil)) if error_event_supported?
  query = query.where(scheduled_at: ..Time.now).or(query.where(scheduled_at: nil))
  query.count
end