Module: HireFire::Macro::Deprecated::Sidekiq

Included in:
Sidekiq
Defined in:
lib/hirefire/macro/deprecated/sidekiq.rb

Overview

Provides backward compatibility with the deprecated Sidekiq macro. For new implementations, refer to Sidekiq.

Instance Method Summary collapse

Instance Method Details

#latency(queue = "default") ⇒ Float

Calculates the latency (in seconds) for the specified Sidekiq queue.

The method uses the Sidekiq::Queue class to obtain the latency of a queue, which is the duration since the oldest job in the queue was enqueued.

Examples:

Calculating latency for the default queue

HireFire::Macro::Sidekiq.latency

Calculating latency for the “critical” queue

HireFire::Macro::Sidekiq.latency("critical")

Parameters:

  • queue (String, Symbol) (defaults to: "default")

    The name of the queue to measure latency. Defaults to “default” if no queue name is provided.

Returns:

  • (Float)

    The latency of the queue in seconds.



21
22
23
# File 'lib/hirefire/macro/deprecated/sidekiq.rb', line 21

def latency(queue = "default")
  ::Sidekiq::Queue.new(queue.to_s).latency
end

#queue(*args) ⇒ Integer

Counts the number of jobs in the specified Sidekiq queue(s).

The method supports various options to include or exclude jobs from specific sets like scheduled, retries, or in-progress jobs.

Examples:

Counting jobs in all queues

HireFire::Macro::Sidekiq.queue

Counting jobs in the “default” and “critical” queues

HireFire::Macro::Sidekiq.queue("default", "critical")

Counting jobs in the “default” queue, excluding scheduled jobs

HireFire::Macro::Sidekiq.queue("default", skip_scheduled: true)

Counting jobs in the “default” queue, excluding retryable jobs

HireFire::Macro::Sidekiq.queue("default", skip_retries: true)

Counting jobs in the “default” queue, excluding in-progress jobs

HireFire::Macro::Sidekiq.queue("default", skip_working: true)

Parameters:

  • args (Array<String, Symbol, Hash>)

    Queue names to count jobs in and an optional hash of options. Pass an empty array or no arguments to count jobs in all queues. The last argument can be a Hash of options to modify the count behavior. Possible keys are :skip_scheduled, :skip_retries, :skip_working. These keys are booleans which default to false.

Returns:

  • (Integer)

    Total number of jobs in the specified queues.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/hirefire/macro/deprecated/sidekiq.rb', line 46

def queue(*args)
  require "sidekiq/api"

  args.flatten!

  options = args.last.is_a?(Hash) ? args.pop : {}
  queues = args.map(&:to_s)
  all_queues = ::Sidekiq::Queue.all.map(&:name)
  queues = all_queues if queues.empty?

  if fast_lookup_capable?(queues, all_queues)
    fast_lookup(options)
  else
    dynamic_lookup(queues, options)
  end
end