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
- #after_perform_analytics(*args) ⇒ Object
- #analytics_timestamp(timestamp) ⇒ Object
- #around_perform_analytics(*args) ⇒ Object
- #field(kpi) ⇒ Object
- #key ⇒ Object
- #on_failure_analytics(error, *args) ⇒ Object
- #redis_command(command, key, field, timestamp = 1) ⇒ Object
Class Method Details
.ignore_classes ⇒ Object
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 () redis_command("hincrbyfloat", key, field(WAIT_TIME), Time.now - Time.parse()) 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 |
#key ⇒ Object
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, = 1) tries ||= 3 Resque.redis.send(command, key, field, ) Resque.redis.expire(key, EXPIRE) rescue Redis::TimeoutError, Redis::CannotConnectError retry if (tries -= 1).nonzero? end |