Class: SidekiqHerokuScaler::Worker

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq-heroku-scaler/worker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_nameObject (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

#concurrencyObject



15
16
17
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 15

def concurrency
  process['concurrency'] || 0
end

#formation_idObject



19
20
21
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 19

def formation_id
  formation.id
end

#jobs_running?Boolean

Returns:

  • (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

#latencyObject



31
32
33
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 31

def latency
  queues.sum { |queue| Sidekiq::Queue.new(queue).latency }
end

#processesObject



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

#quantityObject



23
24
25
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 23

def quantity
  formation.quantity
end

#queues_sizeObject



35
36
37
# File 'lib/sidekiq-heroku-scaler/worker.rb', line 35

def queues_size
  queues.sum { |queue| Sidekiq::Queue.new(queue).size }
end