class Sidekiq::Statistic::Realtime
Constants
- DAYS_PREVIOUS
Public Class Methods
charts_initializer()
click to toggle source
# File lib/sidekiq/statistic/statistic/realtime.rb, line 8 def self.charts_initializer workers = new.worker_names.map{ |w| Array.new(12, 0).unshift(w) } workers << Array.new(12) { |i| (Time.now - i).strftime('%T') }.unshift('x') workers end
new()
click to toggle source
# File lib/sidekiq/statistic/statistic/realtime.rb, line 14 def initialize @start_date = Time.now.utc.to_date @end_date = @start_date - DAYS_PREVIOUS end
Public Instance Methods
realtime_hash()
click to toggle source
# File lib/sidekiq/statistic/statistic/realtime.rb, line 19 def realtime_hash Sidekiq.redis do |conn| redis_hash = {} conn .hgetall("#{REDIS_HASH}:realtime:#{Time.now.sec - 1}") .each do |keys, value| *keys, last = keys.split(KEY_SEPARATOR) keys.inject(redis_hash, &key_or_empty_hash)[last] = value.to_i end redis_hash end end
statistic(params = {})
click to toggle source
# File lib/sidekiq/statistic/statistic/realtime.rb, line 33 def statistic(params = {}) { failed: { columns: columns_for('failed', params) }, passed: { columns: columns_for('passed', params) } } end
Private Instance Methods
axis_array()
click to toggle source
# File lib/sidekiq/statistic/statistic/realtime.rb, line 54 def axis_array @array ||= ['x', Time.now.strftime('%T')] end
columns_for(status, params = {})
click to toggle source
# File lib/sidekiq/statistic/statistic/realtime.rb, line 42 def columns_for(status, params = {}) workers = params['excluded'] ? worker_names - Array(params['excluded']) : worker_names workers.map do |worker| [worker, realtime.fetch(status, {})[worker] || 0] end << axis_array end
realtime()
click to toggle source
# File lib/sidekiq/statistic/statistic/realtime.rb, line 50 def realtime @realtime_hash ||= realtime_hash end