Skip to content

Commit

Permalink
Custom job durations working.
Browse files Browse the repository at this point in the history
  • Loading branch information
alanpeabody committed Sep 24, 2011
1 parent f44d070 commit 84fa937
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions lib/resque/plugins/job_stats/duration.rb
Expand Up @@ -10,7 +10,7 @@ def reset_job_durations

# Returns the number of jobs failed
def job_durations
Resque.redis.lrange(jobs_duration_key,0,job_durations_to_track).map(&:to_f)
Resque.redis.lrange(jobs_duration_key,0,durations_recorded - 1).map(&:to_f)
end

# Returns the key used for tracking job durations
Expand All @@ -25,11 +25,11 @@ def around_perform_job_stats_duration(*payload)
duration = Time.now - start

Resque.redis.lpush(jobs_duration_key, duration)
Resque.redis.ltrim(jobs_duration_key, 0, job_durations_to_track)
Resque.redis.ltrim(jobs_duration_key, 0, durations_recorded)
end

def job_durations_to_track
100
def durations_recorded
@durations_recorded || 100
end

def job_rolling_avg
Expand Down
4 changes: 2 additions & 2 deletions test/test_job_stats.rb
Expand Up @@ -83,12 +83,12 @@ def test_duration
def test_custom_duration
CustomDurJob.reset_job_durations

2.times do |i|
2.times do
Resque.enqueue(CustomDurJob,1.0)
@worker.work(0)
end

5.times do |i|
5.times do
Resque.enqueue(CustomDurJob,0.1)
@worker.work(0)
end
Expand Down

0 comments on commit 84fa937

Please sign in to comment.