Module: Resque::Plugins::History

Defined in:
lib/version.rb,
lib/resque-history/plugins/history.rb

Constant Summary collapse

VERSION =
"0.0.1"
MAX_HISTORY_SIZE =
500
HISTORY_SET_NAME =
"resque_history"

Instance Method Summary collapse

Instance Method Details

#after_perform_history(*args) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/resque-history/plugins/history.rb', line 30

def after_perform_history(*args)
  elapsed_seconds = (Time.now - @start_time).to_i
  Resque.redis.lpush(HISTORY_SET_NAME, {:class => "#{self}",
                                        :args => args,
                                        :time => Time.now.strftime("%Y-%m-%d %H:%M:%S %z"),
                                        :execution =>elapsed_seconds
  }.to_json)

  if Resque.redis.llen(HISTORY_SET_NAME) > maximum_history_size
    Resque.redis.rpop(HISTORY_SET_NAME)
  end

end

#before_perform_history(*args) ⇒ Object



26
27
28
# File 'lib/resque-history/plugins/history.rb', line 26

def before_perform_history(*args)
  @start_time = Time.now
end

#maximum_history_sizeObject



8
9
10
# File 'lib/resque-history/plugins/history.rb', line 8

def maximum_history_size
  @max_history ||= MAX_HISTORY_SIZE
end

#on_failure_history(exception, *args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/resque-history/plugins/history.rb', line 12

def on_failure_history(exception, *args)
  Resque.redis.lpush(HISTORY_SET_NAME, {:class => "#{self}",
                                        :time => Time.now.strftime("%Y-%m-%d %H:%M:%S %z"),
                                        :args => args,
                                        :error => exception.message
  }.to_json)

  if Resque.redis.llen(HISTORY_SET_NAME) > maximum_history_size
    Resque.redis.rpop(HISTORY_SET_NAME)
  end

end