module Resque::Plugins::Analytics

Constants

EXPIRE
FAILED
PERFORMED
TOTAL_TIME
WAIT_TIME

Public Class Methods

ignore_classes() click to toggle source
# File lib/resque/plugins/analytics.rb, line 41
def self.ignore_classes
  @ignore_classes || []
end
ignore_classes=(class_array) click to toggle source
# File lib/resque/plugins/analytics.rb, line 37
def self.ignore_classes=(class_array)
  @ignore_classes = class_array
end

Public Instance Methods

after_perform_analytics(*args) click to toggle source
# File lib/resque/plugins/analytics.rb, line 61
def after_perform_analytics(*args)
  redis_command("hincrby", key, field(PERFORMED))
end
analytics_timestamp(timestamp) click to toggle source
# File lib/resque/plugins/analytics.rb, line 69
def analytics_timestamp(timestamp)
  redis_command("hincrbyfloat", key, field(WAIT_TIME), Time.now - Time.parse(timestamp))
end
around_perform_analytics(*args) { || ... } click to toggle source
# File lib/resque/plugins/analytics.rb, line 54
def around_perform_analytics(*args)
  start = Time.now
  yield
  total_time = Time.now - start
  redis_command("hincrbyfloat", key, field(TOTAL_TIME), total_time)
end
field(kpi) click to toggle source
# File lib/resque/plugins/analytics.rb, line 50
def field(kpi)
  "#{self.name}:#{kpi}"
end
key() click to toggle source
# File lib/resque/plugins/analytics.rb, line 45
def key
  date = Time.now.strftime("%y_%m_%d")
  "resque-analytics:#{date}"
end
on_failure_analytics(error, *args) click to toggle source
# File lib/resque/plugins/analytics.rb, line 65
def on_failure_analytics(error, *args)
  redis_command("hincrby", key, field(FAILED))
end
redis_command(command, key, field, timestamp = 1) click to toggle source
# File lib/resque/plugins/analytics.rb, line 73
def redis_command(command, key, field, timestamp = 1)
  tries ||= 3
  Resque.redis.send(command, key, field, timestamp)
  Resque.redis.expire(key, EXPIRE)
rescue Redis::TimeoutError, Redis::CannotConnectError
  retry if (tries -= 1).nonzero?
end