Module: HireFire::Macro::QC

Extended by:
Deprecated::QC, QC, Utility
Included in:
QC
Defined in:
lib/hirefire/macro/queue_classic.rb

Instance Method Summary collapse

Methods included from Deprecated::QC

queue

Instance Method Details

#job_queue_latency(*queues) ⇒ Float

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

Examples:

Calculate latency across all queues

HireFire::Macro::QC.job_queue_latency

Calculate latency for the “default” queue

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

Calculate latency across “default” and “mailer” queues

HireFire::Macro::QC.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.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/hirefire/macro/queue_classic.rb', line 24

def job_queue_latency(*queues)
  queues = normalize_queues(queues, allow_empty: true)

  query = <<~SQL
    SELECT EXTRACT(EPOCH FROM (now() - scheduled_at)) AS latency
    FROM #{::QC.table_name}
    WHERE scheduled_at <= now()
    #{filter_by_queues_if_any(queues)}
    ORDER BY scheduled_at ASC
    LIMIT 1
  SQL

  connection = ::QC.default_conn_adapter

  result = if queues.any?
    connection.execute(query, "{#{queues.to_a.join(",")}}")
  else
    connection.execute(query)
  end

  (result && result["latency"]) ? result["latency"].to_f : 0.0
end

#job_queue_size(*queues) ⇒ Integer

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

Examples:

Calculate size across all queues

HireFire::Macro::QC.job_queue_size

Calculate size for the “default” queue

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

Calculate size across “default” and “mailer” queues

HireFire::Macro::QC.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.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/hirefire/macro/queue_classic.rb', line 59

def job_queue_size(*queues)
  queues = normalize_queues(queues, allow_empty: true)

  query = <<~SQL
    SELECT COUNT(*) FROM #{::QC.table_name}
    WHERE scheduled_at <= now()
    #{filter_by_queues_if_any(queues)}
  SQL

  connection = ::QC.default_conn_adapter

  result = if queues.any?
    connection.execute(query, "{#{queues.to_a.join(",")}}")
  else
    connection.execute(query)
  end

  result["count"].to_i
end