Module: Resque::Plugins::Analytics

Defined in:
lib/resque-analytics/server.rb,
lib/resque/plugins/analytics.rb

Defined Under Namespace

Modules: Server

Constant Summary collapse

FAILED =
"failed"
PERFORMED =
"performed"
TOTAL_TIME =
"total_time"
WAIT_TIME =
"wait_time"
EXPIRE =
90.days.to_i

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ignore_classesObject



41
42
43
# File 'lib/resque/plugins/analytics.rb', line 41

def self.ignore_classes
  @ignore_classes || []
end

.ignore_classes=(class_array) ⇒ Object



37
38
39
# File 'lib/resque/plugins/analytics.rb', line 37

def self.ignore_classes=(class_array)
  @ignore_classes = class_array
end

Instance Method Details

#after_perform_analytics(*args) ⇒ Object



61
62
63
# File 'lib/resque/plugins/analytics.rb', line 61

def after_perform_analytics(*args)
  redis_command("hincrby", key, field(PERFORMED))
end

#analytics_timestamp(timestamp) ⇒ Object



69
70
71
# 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) ⇒ Object



54
55
56
57
58
59
# 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) ⇒ Object



50
51
52
# File 'lib/resque/plugins/analytics.rb', line 50

def field(kpi)
  "#{self.name}:#{kpi}"
end

#keyObject



45
46
47
48
# 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) ⇒ Object



65
66
67
# 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) ⇒ Object



73
74
75
76
77
78
79
# 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