Class: SidekiqAutoscale::SidekiqInterface

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq_autoscale/sidekiq_interface.rb

Instance Method Summary collapse

Instance Method Details

#available_threadsObject



36
37
38
# File 'lib/sidekiq_autoscale/sidekiq_interface.rb', line 36

def available_threads
  total_threads - busy_threads
end

#busy_threadsObject



20
21
22
# File 'lib/sidekiq_autoscale/sidekiq_interface.rb', line 20

def busy_threads
  ::Sidekiq::Workers.new.map {|_, thread, _| thread }.uniq.size
end

#latencyObject



24
25
26
# File 'lib/sidekiq_autoscale/sidekiq_interface.rb', line 24

def latency
  queue_names.map {|q| ::Sidekiq::Queue.new(q).latency }.max
end

#queue_namesObject



11
12
13
14
15
16
17
18
# File 'lib/sidekiq_autoscale/sidekiq_interface.rb', line 11

def queue_names
  from_env = ENV["SIDEKIQ_QUEUES"]
  if from_env
    JSON.parse(from_env)
  else
    ::Sidekiq::Queue.all.map(&:name)
  end
end

#total_queue_sizeObject



7
8
9
# File 'lib/sidekiq_autoscale/sidekiq_interface.rb', line 7

def total_queue_size
  queue_names.map {|q| ::Sidekiq::Queue.new(q).size }.reduce(0, &:+)
end

#total_threadsObject



32
33
34
# File 'lib/sidekiq_autoscale/sidekiq_interface.rb', line 32

def total_threads
  process_set.map {|w| w["concurrency"] }.reduce(0, &:+)
end

#total_workersObject



28
29
30
# File 'lib/sidekiq_autoscale/sidekiq_interface.rb', line 28

def total_workers
  process_set.size
end

#youngest_workerObject



40
41
42
# File 'lib/sidekiq_autoscale/sidekiq_interface.rb', line 40

def youngest_worker
  process_set.map {|w| w["started_at"] }.max
end