Class: SidekiqHerokuScaler::Worker
- Inherits:
-
Object
- Object
- SidekiqHerokuScaler::Worker
- Defined in:
- lib/sidekiq-heroku-scaler/worker.rb
Instance Attribute Summary collapse
-
#worker_name ⇒ Object
readonly
Returns the value of attribute worker_name.
Instance Method Summary collapse
- #concurrency ⇒ Object
- #formation_id ⇒ Object
-
#initialize(worker_name, formation) ⇒ Worker
constructor
A new instance of Worker.
- #jobs_running? ⇒ Boolean
- #latency ⇒ Object
- #processes ⇒ Object
- #quantity ⇒ Object
- #queues_size ⇒ Object
Constructor Details
#initialize(worker_name, formation) ⇒ Worker
Returns a new instance of Worker.
10 11 12 13 |
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 10 def initialize(worker_name, formation) @worker_name = worker_name @formation = formation end |
Instance Attribute Details
#worker_name ⇒ Object (readonly)
Returns the value of attribute worker_name.
8 9 10 |
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 8 def worker_name @worker_name end |
Instance Method Details
#concurrency ⇒ Object
15 16 17 |
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 15 def concurrency process['concurrency'] || 0 end |
#formation_id ⇒ Object
19 20 21 |
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 19 def formation_id formation.id end |
#jobs_running? ⇒ Boolean
27 28 29 |
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 27 def jobs_running? Sidekiq::Workers.new.any? { |_process_id, _thread_id, work| queues.include?(work['queue']) } end |
#latency ⇒ Object
31 32 33 |
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 31 def latency queues.sum { |queue| Sidekiq::Queue.new(queue).latency } end |
#processes ⇒ Object
39 40 41 |
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 39 def processes @processes ||= Sidekiq::ProcessSet.new.select { |process| process.identity.match?(/\A#{worker_name}\./) } end |
#quantity ⇒ Object
23 24 25 |
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 23 def quantity formation.quantity end |
#queues_size ⇒ Object
35 36 37 |
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 35 def queues_size queues.sum { |queue| Sidekiq::Queue.new(queue).size } end |