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
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
58 59 60 |
# File 'lib/resque/plugins/analytics.rb', line 58 def after_perform_analytics(*args) redis_command("hincrby", key, field(PERFORMED)) end |
#analytics_timestamp(timestamp) ⇒ Object
66 67 68 |
# File 'lib/resque/plugins/analytics.rb', line 66 def () redis_command("hincrbyfloat", key, field(WAIT_TIME), Time.now - Time.parse()) end |
#around_perform_analytics(*args) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/resque/plugins/analytics.rb', line 51 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
47 48 49 |
# File 'lib/resque/plugins/analytics.rb', line 47 def field(kpi) "#{self.name}:#{kpi}" end |
#key ⇒ Object
42 43 44 45 |
# File 'lib/resque/plugins/analytics.rb', line 42 def key date = Time.now.strftime("%y_%m_%d") "resque-analytics:#{date}" end |
#on_failure_analytics(error, *args) ⇒ Object
62 63 64 |
# File 'lib/resque/plugins/analytics.rb', line 62 def on_failure_analytics(error, *args) redis_command("hincrby", key, field(FAILED)) end |
#redis_command(command, key, field, timestamp = 1) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/resque/plugins/analytics.rb', line 70 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 |