Class: Autoscaler::Sidekiq::SpecifiedQueueSystem

Inherits:
Object
  • Object
show all
Defined in:
lib/autoscaler/sidekiq/specified_queue_system.rb

Overview

Interface to to interrogate the queuing system Includes only the queues provided to the constructor

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(specified_queues) ⇒ SpecifiedQueueSystem

Returns a new instance of SpecifiedQueueSystem.

Parameters:

  • specified_queues (Array[String])

    list of queues to monitor to determine if there is work left. Defaults to all sidekiq queues.



9
10
11
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 9

def initialize(specified_queues)
  @queue_names = specified_queues
end

Instance Attribute Details

#queue_namesArray[String] (readonly)

Returns:

  • (Array[String])


46
47
48
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 46

def queue_names
  @queue_names
end

Instance Method Details

#any_work?Boolean

Returns if any kind of work still needs to be done.

Returns:

  • (Boolean)

    if any kind of work still needs to be done



36
37
38
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 36

def any_work?
  queued > 0 || scheduled > 0 || retrying > 0 || workers > 0
end

#queuedInteger

Returns amount work ready to go.

Returns:

  • (Integer)

    amount work ready to go



21
22
23
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 21

def queued
  queue_names.map {|name| sidekiq_queues[name].to_i}.reduce(&:+)
end

#retryingInteger

Returns amount of work still being retried.

Returns:

  • (Integer)

    amount of work still being retried



31
32
33
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 31

def retrying
  count_set(::Sidekiq::RetrySet.new)
end

#scheduledInteger

Returns amount of work scheduled for some time in the future.

Returns:

  • (Integer)

    amount of work scheduled for some time in the future



26
27
28
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 26

def scheduled
  count_set(::Sidekiq::ScheduledSet.new)
end

#total_workInteger

Returns total amount of work.

Returns:

  • (Integer)

    total amount of work



41
42
43
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 41

def total_work
  queued + scheduled + retrying + workers
end

#workersInteger

Returns number of workers actively engaged.

Returns:

  • (Integer)

    number of workers actively engaged



14
15
16
17
18
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 14

def workers
  ::Sidekiq::Workers.new.select {|_, _, work|
    queue_names.include?(work['queue'])
  }.map {|pid, _, _| pid}.uniq.size
end