class QPush::Web::Apis::Stats

Constants

DEFAULTS

Public Class Methods

new() click to toggle source
# File lib/qpush/web/apis/stats.rb, line 17
def initialize
  @stats = nil
end

Public Instance Methods

call() click to toggle source
# File lib/qpush/web/apis/stats.rb, line 21
def call
  retrieve_stats
  apply_defaults
  calculate_stats
  @stats
end

Private Instance Methods

apply_defaults() click to toggle source
# File lib/qpush/web/apis/stats.rb, line 36
def apply_defaults
  @stats.each { |k, v| @stats[k] = v.to_i }
  @stats = DEFAULTS.merge(@stats)
end
calculate_current() click to toggle source
# File lib/qpush/web/apis/stats.rb, line 50
def calculate_current
  Web.redis do |c|
    Web.keys[:perform_list].collect { |list| c.llen(list) }.reduce(:+)
  end
end
calculate_stats() click to toggle source
# File lib/qpush/web/apis/stats.rb, line 41
def calculate_stats
  @stats['percent_success'] = calculate_success
  @stats['current_queue'] = calculate_current
end
calculate_success() click to toggle source
# File lib/qpush/web/apis/stats.rb, line 46
def calculate_success
  (100.00 - ((@stats['failed'].to_f / @stats['performed'].to_f) * 100.00)).round(2)
end
retrieve_stats() click to toggle source
# File lib/qpush/web/apis/stats.rb, line 30
def retrieve_stats
  @stats = Web.redis do |conn|
    conn.hgetall(Web.keys[:stats])
  end
end