class SidekiqErr::View
Constants
- COL_PAD
- QUEUE_STRUCT
Attributes
section[R]
Public Class Methods
new(section)
click to toggle source
# File lib/sidekiq-err/view.rb, line 13 def initialize(section) @section = section end
valid_sections()
click to toggle source
# File lib/sidekiq-err/view.rb, line 9 def self.valid_sections @valid_sections ||= %w[all version overview processes queues].freeze end
Public Instance Methods
all()
click to toggle source
# File lib/sidekiq-err/view.rb, line 27 def all version puts overview puts processes puts queues end
display()
click to toggle source
# File lib/sidekiq-err/view.rb, line 17 def display if invalid_section?(section) msg = "Invalid section for status check: '#{section}'" msg += "\nTry one of these: #{self.class.valid_sections.join(', ')}" raise(InvalidSection, msg) end send(section) end
overview()
click to toggle source
# File lib/sidekiq-err/view.rb, line 42 def overview puts '---- Overview ----' puts " Processed: #{delimit stats.processed}" puts " Failed: #{delimit stats.failed}" puts " Busy: #{delimit stats.workers_size}" puts " Enqueued: #{delimit stats.enqueued}" puts " Retries: #{delimit stats.retry_size}" puts " Scheduled: #{delimit stats.scheduled_size}" puts " Dead: #{delimit stats.dead_size}" end
processes()
click to toggle source
# File lib/sidekiq-err/view.rb, line 53 def processes puts "---- Processes (#{process_set.size}) ----" process_set.each_with_index do |process, index| puts "#{process['identity']} #{tags_for(process)}" puts " Started: #{Time.at(process['started_at'])} (#{time_ago(process['started_at'])})" puts " Threads: #{process['concurrency']} (#{process['busy']} busy)" puts " Queues: #{split_multiline(process['queues'].sort, pad: 11)}" puts '' unless (index+1) == process_set.size end end
queues()
click to toggle source
# File lib/sidekiq-err/view.rb, line 65 def queues puts "---- Queues (#{queue_data.size}) ----" columns = { name: [:ljust, (['name'] + queue_data.map(&:name)).map(&:length).max + COL_PAD], size: [:rjust, (['size'] + queue_data.map(&:size)).map(&:length).max + COL_PAD], latency: [:rjust, (['latency'] + queue_data.map(&:latency)).map(&:length).max + COL_PAD] } columns.each { |col, (dir, width)| print col.to_s.upcase.public_send(dir, width) } puts queue_data.each do |q| columns.each do |col, (dir, width)| print q.send(col).public_send(dir, width) end puts end end
version()
click to toggle source
# File lib/sidekiq-err/view.rb, line 37 def version puts "Sidekiq #{Sidekiq::VERSION}" puts Time.now.utc end
Private Instance Methods
delimit(number)
click to toggle source
# File lib/sidekiq-err/view.rb, line 84 def delimit(number) number.to_s.reverse.scan(/.{1,3}/).join(',').reverse end
invalid_section?(section)
click to toggle source
# File lib/sidekiq-err/view.rb, line 140 def invalid_section?(section) !self.class.valid_sections.include?(section) end
process_set()
click to toggle source
# File lib/sidekiq-err/view.rb, line 132 def process_set @process_set ||= Sidekiq::ProcessSet.new end
queue_data()
click to toggle source
# File lib/sidekiq-err/view.rb, line 126 def queue_data @queue_data ||= Sidekiq::Queue.all.map do |q| QUEUE_STRUCT.new(q.name, q.size.to_s, sprintf('%#.2f', q.latency)) end end
split_multiline(values, opts = {})
click to toggle source
# File lib/sidekiq-err/view.rb, line 88 def split_multiline(values, opts = {}) return 'none' unless values pad = opts[:pad] || 0 max_length = opts[:max_length] || (80 - pad) out = [] line = ''.dup values.each do |value| if (line.length + value.length) > max_length out += line line = ' ' * pad end line += "#{value}, " end out << line[0..-3] out.join("\n") end
stats()
click to toggle source
# File lib/sidekiq-err/view.rb, line 136 def stats @stats ||= Sidekiq::Stats.new end
time_ago(timestamp)
click to toggle source
# File lib/sidekiq-err/view.rb, line 115 def time_ago(timestamp) seconds = Time.now - Time.at(timestamp) return 'just now' if seconds < 60 return 'a minute ago' if seconds < 120 return "#{seconds.floor / 60} minutes ago" if seconds < 3600 return 'an hour ago' if seconds < 7200 "#{seconds.floor / 60 / 60} hours ago" end