Class: Resque::Failure::Redis
- Inherits:
-
Base
- Object
- Base
- Resque::Failure::Redis
show all
- Defined in:
- lib/resque/failure/redis.rb
Overview
A Failure backend that stores exceptions in Redis. Very simple but works out of the box, along with support in the Resque web app.
Instance Attribute Summary
Attributes inherited from Base
#exception, #payload, #queue, #worker
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Base
#initialize, #log, search_count, search_results, url
Class Method Details
.all(start = 0, count = 1) ⇒ Object
24
25
26
|
# File 'lib/resque/failure/redis.rb', line 24
def self.all(start = 0, count = 1)
Resque.list_range(:failed, start, count)
end
|
.clear ⇒ Object
28
29
30
|
# File 'lib/resque/failure/redis.rb', line 28
def self.clear
Resque.redis.del(:failed)
end
|
.count ⇒ Object
20
21
22
|
# File 'lib/resque/failure/redis.rb', line 20
def self.count
Resque.redis.llen(:failed).to_i
end
|
.remove(index) ⇒ Object
39
40
41
42
43
|
# File 'lib/resque/failure/redis.rb', line 39
def self.remove(index)
id = rand(0xffffff)
Resque.redis.lset(:failed, index, id)
Resque.redis.lrem(:failed, 1, id)
end
|
.requeue(index) ⇒ Object
32
33
34
35
36
37
|
# File 'lib/resque/failure/redis.rb', line 32
def self.requeue(index)
item = all(index)
item['retried_at'] = Time.now.strftime("%Y/%m/%d %H:%M:%S")
Resque.redis.lset(:failed, index, Resque.encode(item))
Job.create(item['queue'], item['payload']['class'], *item['payload']['args'])
end
|
Instance Method Details
#filter_backtrace(backtrace) ⇒ Object
45
46
47
48
|
# File 'lib/resque/failure/redis.rb', line 45
def filter_backtrace(backtrace)
index = backtrace.index { |item| item.include?('/lib/resque/job.rb') }
backtrace.first(index.to_i)
end
|
#save ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
|
# File 'lib/resque/failure/redis.rb', line 6
def save
data = {
:failed_at => Time.now.strftime("%Y/%m/%d %H:%M:%S"),
:payload => payload,
:exception => exception.class.to_s,
:error => exception.to_s,
:backtrace => filter_backtrace(Array(exception.backtrace)),
:worker => worker.to_s,
:queue => queue
}
data = Resque.encode(data)
Resque.redis.rpush(:failed, data)
end
|