Module: Resque::Plugins::JobStats::Duration
- Includes:
- MeasuredHook
- Included in:
- Resque::Plugins::JobStats
- Defined in:
- lib/resque/plugins/job_stats/duration.rb
Instance Method Summary collapse
-
#around_perform_job_stats_duration(*args) ⇒ Object
Increments the failed count when job is complete.
- #durations_recorded ⇒ Object
-
#job_durations ⇒ Object
Returns the number of jobs failed.
- #job_rolling_avg ⇒ Object
-
#jobs_duration_key ⇒ Object
Returns the key used for tracking job durations.
- #longest_job ⇒ Object
-
#reset_job_durations ⇒ Object
Resets all job durations.
Methods included from MeasuredHook
Instance Method Details
#around_perform_job_stats_duration(*args) ⇒ Object
Increments the failed count when job is complete
23 24 25 26 27 28 29 30 |
# File 'lib/resque/plugins/job_stats/duration.rb', line 23 def around_perform_job_stats_duration(*args) start = Time.now yield duration = Time.now - start Resque.redis.lpush(jobs_duration_key, duration) Resque.redis.ltrim(jobs_duration_key, 0, durations_recorded) end |
#durations_recorded ⇒ Object
32 33 34 |
# File 'lib/resque/plugins/job_stats/duration.rb', line 32 def durations_recorded @durations_recorded || 100 end |
#job_durations ⇒ Object
Returns the number of jobs failed
13 14 15 |
# File 'lib/resque/plugins/job_stats/duration.rb', line 13 def job_durations Resque.redis.lrange(jobs_duration_key,0,durations_recorded - 1).map(&:to_f) end |
#job_rolling_avg ⇒ Object
36 37 38 39 40 |
# File 'lib/resque/plugins/job_stats/duration.rb', line 36 def job_rolling_avg job_times = job_durations return 0.0 if job_times.size == 0.0 job_times.inject(0.0) {|s,j| s + j} / job_times.size end |
#jobs_duration_key ⇒ Object
Returns the key used for tracking job durations
18 19 20 |
# File 'lib/resque/plugins/job_stats/duration.rb', line 18 def jobs_duration_key "stats:jobs:#{self.name}:duration" end |
#longest_job ⇒ Object
42 43 44 |
# File 'lib/resque/plugins/job_stats/duration.rb', line 42 def longest_job job_durations.max.to_f end |
#reset_job_durations ⇒ Object
Resets all job durations
8 9 10 |
# File 'lib/resque/plugins/job_stats/duration.rb', line 8 def reset_job_durations Resque.redis.del(jobs_duration_key) end |