Module: HireFire::Macro::SolidQueue

Extended by:
SolidQueue, Utility
Included in:
SolidQueue
Defined in:
lib/hirefire/macro/solid_queue.rb

Constant Summary collapse

LATENCY_METHODS =
[
  :ready_latency,
  :scheduled_latency,
  :blocked_latency
].freeze
SIZE_METHODS =
[
  :ready_size,
  :scheduled_size,
  :claimed_size,
  :blocked_size
].freeze

Instance Method Summary collapse

Instance Method Details

#job_queue_latency(*queues) ⇒ Float

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

This function measures the job queue latency across the Ready, Scheduled, and Blocked queues, based on the enqueue, schedule, and expiration times of their executions. Executions in the Claimed queue, as well as in paused queues, are excluded from the calculation.

Examples:

Calculate latency across all queues

HireFire::Macro::SolidQueue.job_queue_latency

Calculate latency for the “default” queue

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

Calculate latency across “default” and “mailer” queues

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

Calculate latency across “mailer_*” queues (i.e. mailer_notification, mailer_newsletter)

HireFire::Macro::SolidQueue.job_queue_latency(:"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.



33
34
35
36
37
38
39
# File 'lib/hirefire/macro/solid_queue.rb', line 33

def job_queue_latency(*queues)
  queues, now = determine_queues(queues), Time.now

  LATENCY_METHODS.map do |latency_method|
    method(latency_method).call(queues, now: now)
  end.max
end

#job_queue_size(*queues) ⇒ Integer

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

This function measures the job queue latency across the Ready, Scheduled, Blocked, and Claimed queues, based on the schedule and expiration times of their executions. Executions in paused queues are excluded from the calculation.

Examples:

Calculate size across all queues

HireFire::Macro::SolidQueue.job_queue_size

Calculate size for the “default” queue

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

Calculate size across “default” and “mailer” queues

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

Calculate size across “mailer_*” queues (i.e. mailer_notification, mailer_newsletter)

HireFire::Macro::SolidQueue.job_queue_size(:"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.



66
67
68
69
70
71
72
# File 'lib/hirefire/macro/solid_queue.rb', line 66

def job_queue_size(*queues)
  queues = determine_queues(queues)

  SIZE_METHODS.sum do |count_method|
    method(count_method).call(queues)
  end
end