Module: Resque::Plugins::JobStats::History

Includes:
Helpers
Included in:
Resque::Plugins::JobStats
Defined in:
lib/resque/plugins/job_stats/history.rb

Instance Method Summary collapse

Instance Method Details

#around_perform_job_stats_history(*args) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/resque/plugins/job_stats/history.rb', line 16

def around_perform_job_stats_history(*args)
  # we collect our own duration and start time rather
  # than correlate with the duration stat to make sure
  # we're associating them with the right job arguments
  start = Time.now
  begin
    yield
    duration = Time.now - start
    push_history "success" => true, "args" => args, "run_at" => start, "duration" => duration
  rescue Exception => e
    duration = Time.now - start
    exception = { "name" => e.to_s, "backtrace" => e.backtrace }
    push_history "success" => false, "exception" => exception, "args" => args, "run_at" => start, "duration" => duration
    raise e
  end
end

#histories_recordableObject



33
34
35
# File 'lib/resque/plugins/job_stats/history.rb', line 33

def histories_recordable
  @histories_recordable || 100
end

#histories_recordedObject



37
38
39
# File 'lib/resque/plugins/job_stats/history.rb', line 37

def histories_recorded
  Resque.redis.llen(jobs_history_key)
end

#job_histories(start = 0, limit = histories_recordable) ⇒ Object



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

def job_histories(start=0, limit=histories_recordable)
  Resque.redis.lrange(jobs_history_key, start, start + limit - 1).map { |h| decode(h) }
end

#jobs_history_keyObject

Returns the key used for tracking job histories



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

def jobs_history_key
  "stats:jobs:#{self.name}:history"
end

#reset_job_historiesObject



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

def reset_job_histories
  Resque.redis.del(jobs_history_key)
end