Module: Resque::Plugins::JobStats::Duration

Included in:
Resque::Plugins::JobStats
Defined in:
lib/resque/plugins/job_stats/duration.rb

Instance Method Summary collapse

Instance Method Details

#around_perform_job_stats_duration(*args) ⇒ Object

Increments the failed count when job is complete



22
23
24
25
26
27
28
29
# File 'lib/resque/plugins/job_stats/duration.rb', line 22

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_recordedObject



31
32
33
# File 'lib/resque/plugins/job_stats/duration.rb', line 31

def durations_recorded
  @durations_recorded || 100
end

#job_durationsObject

Returns the number of jobs failed



12
13
14
# File 'lib/resque/plugins/job_stats/duration.rb', line 12

def job_durations
  Resque.redis.lrange(jobs_duration_key,0,durations_recorded - 1).map(&:to_f)
end

#job_rolling_avgObject



35
36
37
38
39
# File 'lib/resque/plugins/job_stats/duration.rb', line 35

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_keyObject

Returns the key used for tracking job durations



17
18
19
# File 'lib/resque/plugins/job_stats/duration.rb', line 17

def jobs_duration_key
  "stats:jobs:#{self.name}:duration"
end

#longest_jobObject



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

def longest_job
  job_durations.max.to_f
end

#reset_job_durationsObject

Resets all job durations



7
8
9
# File 'lib/resque/plugins/job_stats/duration.rb', line 7

def reset_job_durations
  Resque.redis.del(jobs_duration_key)
end