Class: Autoscaler::Sidekiq::SpecifiedQueueSystem
- Inherits:
-
Object
- Object
- Autoscaler::Sidekiq::SpecifiedQueueSystem
- 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
- #queue_names ⇒ Array[String] readonly
Instance Method Summary collapse
-
#any_work? ⇒ Boolean
If any kind of work still needs to be done.
-
#initialize(specified_queues) ⇒ SpecifiedQueueSystem
constructor
A new instance of SpecifiedQueueSystem.
-
#queued ⇒ Integer
Amount work ready to go.
-
#retrying ⇒ Integer
Amount of work still being retried.
-
#scheduled ⇒ Integer
Amount of work scheduled for some time in the future.
-
#total_work ⇒ Integer
Total amount of work.
-
#workers ⇒ Integer
Number of workers actively engaged.
Constructor Details
#initialize(specified_queues) ⇒ SpecifiedQueueSystem
Returns a new instance of SpecifiedQueueSystem.
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_names ⇒ Array[String] (readonly)
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.
36 37 38 |
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 36 def any_work? queued > 0 || scheduled > 0 || > 0 || workers > 0 end |
#queued ⇒ Integer
Returns 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 |
#retrying ⇒ Integer
Returns amount of work still being retried.
31 32 33 |
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 31 def count_set(::Sidekiq::RetrySet.new) end |
#scheduled ⇒ Integer
Returns 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_work ⇒ Integer
Returns total amount of work.
41 42 43 |
# File 'lib/autoscaler/sidekiq/specified_queue_system.rb', line 41 def total_work queued + scheduled + + workers end |
#workers ⇒ Integer
Returns 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 |