Module: Resque::Failure
- Defined in:
- lib/resque/failure.rb,
lib/resque/failure/base.rb,
lib/resque/failure/redis.rb,
lib/resque/failure/hoptoad.rb,
lib/resque/failure/airbrake.rb,
lib/resque/failure/multiple.rb,
lib/resque/failure/thoughtbot.rb
Overview
The Failure module provides an interface for working with different failure backends.
You can use it to query the failure backend without knowing which specific backend is being used. For instance, the Resque web app uses it to display stats and other information.
Defined Under Namespace
Modules: Thoughtbot Classes: Airbrake, Base, Hoptoad, Multiple, Redis
Class Method Summary collapse
-
.all(start = 0, count = 1) ⇒ Object
Returns an array of all the failures, paginated.
-
.backend ⇒ Object
Returns the current backend class.
-
.backend=(backend) ⇒ Object
Sets the current backend.
-
.clear ⇒ Object
Clear all failure jobs.
-
.count ⇒ Object
Returns the int count of how many failures we have seen.
-
.create(options = {}) ⇒ Object
Creates a new failure, which is delegated to the appropriate backend.
- .remove(index) ⇒ Object
-
.remove_queue(queue) ⇒ Object
Removes all failed jobs in a specific queue.
- .requeue(index) ⇒ Object
-
.requeue_queue(queue) ⇒ Object
Requeues all failed jobs in a specific queue.
-
.url ⇒ Object
The string url of the backend’s web interface, if any.
Class Method Details
.all(start = 0, count = 1) ⇒ Object
Returns an array of all the failures, paginated.
‘start` is the int of the first item in the page, `count` is the number of items to return.
48 49 50 |
# File 'lib/resque/failure.rb', line 48 def self.all(start = 0, count = 1) backend.all(start, count) end |
.backend ⇒ Object
Returns the current backend class. If none has been set, falls back to ‘Resque::Failure::Redis`
33 34 35 36 37 |
# File 'lib/resque/failure.rb', line 33 def self.backend return @backend if @backend require 'resque/failure/redis' @backend = Failure::Redis end |
.backend=(backend) ⇒ Object
27 28 29 |
# File 'lib/resque/failure.rb', line 27 def self.backend=(backend) @backend = backend end |
.clear ⇒ Object
Clear all failure jobs
58 59 60 |
# File 'lib/resque/failure.rb', line 58 def self.clear backend.clear end |
.count ⇒ Object
Returns the int count of how many failures we have seen.
40 41 42 |
# File 'lib/resque/failure.rb', line 40 def self.count backend.count end |
.create(options = {}) ⇒ Object
Creates a new failure, which is delegated to the appropriate backend.
Expects a hash with the following keys:
:exception - The Exception object
:worker - The Worker object who is reporting the failure
:queue - The string name of the queue from which the job was pulled
:payload - The job's payload
16 17 18 |
# File 'lib/resque/failure.rb', line 16 def self.create( = {}) backend.new(*.values_at(:exception, :worker, :queue, :payload)).save end |
.remove(index) ⇒ Object
66 67 68 |
# File 'lib/resque/failure.rb', line 66 def self.remove(index) backend.remove(index) end |
.remove_queue(queue) ⇒ Object
Removes all failed jobs in a specific queue. Queue name should be a string.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/resque/failure.rb', line 84 def self.remove_queue(queue) i=0 while job = Resque::Failure.all(i) if job['queue'] == queue # This will remove the failure from the array so do not increment the index. Resque::Failure.remove(i) else i+=1 end end end |
.requeue(index) ⇒ Object
62 63 64 |
# File 'lib/resque/failure.rb', line 62 def self.requeue(index) backend.requeue(index) end |
.requeue_queue(queue) ⇒ Object
Requeues all failed jobs in a specific queue. Queue name should be a string.
72 73 74 75 76 77 78 79 80 |
# File 'lib/resque/failure.rb', line 72 def self.requeue_queue(queue) i=0 while job = Resque::Failure.all(i) if job['queue'] == queue Resque::Failure.requeue(i) end i+=1 end end |
.url ⇒ Object
The string url of the backend’s web interface, if any.
53 54 55 |
# File 'lib/resque/failure.rb', line 53 def self.url backend.url end |