Class: Sidekiq::Statistic::Realtime

Inherits:
Base
  • Object
show all
Defined in:
lib/sidekiq/statistic/statistic/realtime.rb

Constant Summary collapse

DAYS_PREVIOUS =
30

Constants inherited from Base

Base::KEY_SEPARATOR

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#statistic_for, #statistic_hash, #worker_names

Constructor Details

#initializeRealtime

Returns a new instance of Realtime.



14
15
16
17
# 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

Class Method Details

.charts_initializerObject



8
9
10
11
12
# 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

Instance Method Details

#realtime_hashObject



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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 = {}) ⇒ Object



33
34
35
36
37
38
# 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