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 * 24 * 60

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.ignore_classesObject



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

def self.ignore_classes
  @ignore_classes || []
end

.ignore_classes=(class_array) ⇒ Object



34
35
36
# File 'lib/resque/plugins/analytics.rb', line 34

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

Instance Method Details

#after_perform_analytics(*args) ⇒ Object



56
57
58
59
# File 'lib/resque/plugins/analytics.rb', line 56

def after_perform_analytics(*args)
  Resque.redis.incr(key(PERFORMED))
  Resque.redis.expire(key(WAIT_TIME), EXPIRE)
end

#analytics_timestamp(timestamp) ⇒ Object



66
67
68
69
# File 'lib/resque/plugins/analytics.rb', line 66

def analytics_timestamp(timestamp)
  Resque.redis.lpush(key(WAIT_TIME), Time.now - Time.parse(timestamp))
  Resque.redis.expire(key(WAIT_TIME), EXPIRE)
end

#around_perform_analytics(*args) ⇒ Object



47
48
49
50
51
52
53
54
# File 'lib/resque/plugins/analytics.rb', line 47

def around_perform_analytics(*args)
  start = Time.now
  yield
  total_time = Time.now - start

  Resque.redis.lpush(key(TOTAL_TIME), total_time)
  Resque.redis.expire(key(WAIT_TIME), EXPIRE)
end

#key(kpi) ⇒ Object



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

def key(kpi)
  date = Time.now.strftime("%y_%m_%d")
  "analytics:#{kpi}:#{self.name}:#{date}"
end

#on_failure_analytics(error, *args) ⇒ Object



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

def on_failure_analytics(error, *args)
  Resque.redis.incr(key(FAILED))
  Resque.redis.expire(key(WAIT_TIME), EXPIRE)
end