Module: Resque::Failure
- Defined in:
- lib/resque/failure.rb,
lib/resque/failure/base.rb,
lib/resque/failure/redis.rb,
lib/resque/failure/airbrake.rb,
lib/resque/failure/multiple.rb,
lib/resque/failure/redis_multi_queue.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
Classes: Airbrake, Base, Multiple, Redis, RedisMultiQueue
Class Attribute Summary collapse
-
.generate_failure_ids ⇒ Object
writeonly
Sets the attribute generate_failure_ids.
Class Method Summary collapse
-
.all(offset = 0, limit = 1, queue = nil) ⇒ Object
Returns an array of all the failures, paginated.
-
.backend ⇒ Object
Returns the current backend class.
-
.backend=(backend) ⇒ Object
Sets the current backend.
-
.clear(queue = nil) ⇒ Object
Clear all failure jobs.
- .clear_retried ⇒ Object
-
.count(queue = nil, class_name = nil) ⇒ 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.
-
.each(offset = 0, limit = self.count, queue = nil, class_name = nil, order = 'desc', &block) ⇒ Object
Iterate across all failures with the given options.
-
.failure_queue_name(job_queue_name) ⇒ Object
Obtain the failure queue name for a given job queue.
-
.generate_failure_ids? ⇒ Boolean
Whether failures are given a
failure_idwhen they are built. -
.job_queue_name(failure_queue_name) ⇒ Object
Obtain the job queue name for a given failure queue.
-
.queues ⇒ Object
Returns an array of all the failed queues in the system.
- .remove(id, queue = nil) ⇒ Object
-
.remove_queue(queue) ⇒ Object
Removes all failed jobs in a specific queue.
- .requeue(id, queue = nil) ⇒ Object
-
.requeue_all ⇒ Object
Requeues all failed jobs.
-
.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 Attribute Details
.generate_failure_ids=(value) ⇒ Object (writeonly)
Sets the attribute generate_failure_ids
30 31 32 |
# File 'lib/resque/failure.rb', line 30 def generate_failure_ids=(value) @generate_failure_ids = value end |
Class Method Details
.all(offset = 0, limit = 1, queue = nil) ⇒ Object
Returns an array of all the failures, paginated.
offset is the int of the first item in the page, limit is the
number of items to return.
96 97 98 |
# File 'lib/resque/failure.rb', line 96 def self.all(offset = 0, limit = 1, queue = nil) backend.all(offset, limit, queue) end |
.backend ⇒ Object
Returns the current backend class. If none has been set, falls
back to Resque::Failure::Redis
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/resque/failure.rb', line 55 def self.backend return @backend if @backend case ENV['FAILURE_BACKEND'] when 'redis_multi_queue' require 'resque/failure/redis_multi_queue' @backend = Failure::RedisMultiQueue when 'redis', nil require 'resque/failure/redis' @backend = Failure::Redis else raise ArgumentError, "invalid failure backend: #{FAILURE_BACKEND}" end end |
.backend=(backend) ⇒ Object
48 49 50 |
# File 'lib/resque/failure.rb', line 48 def self.backend=(backend) @backend = backend end |
.clear(queue = nil) ⇒ Object
Clear all failure jobs
111 112 113 |
# File 'lib/resque/failure.rb', line 111 def self.clear(queue = nil) backend.clear(queue) end |
.clear_retried ⇒ Object
115 116 117 118 119 |
# File 'lib/resque/failure.rb', line 115 def self.clear_retried each do |index, job| remove(index) unless job['retried_at'].nil? end end |
.count(queue = nil, class_name = nil) ⇒ Object
Returns the int count of how many failures we have seen.
88 89 90 |
# File 'lib/resque/failure.rb', line 88 def self.count(queue = nil, class_name = nil) backend.count(queue, class_name) 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
:failure_id - Optional id to record this failure under, in place of the
one the backend generates for itself.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/resque/failure.rb', line 18 def self.create( = {}) failure = backend.new(*.values_at(:exception, :worker, :queue, :payload)) # Backends are not required to accept an id. if [:failure_id] && failure.respond_to?(:failure_id=) failure.failure_id = [:failure_id] end failure.save end |
.each(offset = 0, limit = self.count, queue = nil, class_name = nil, order = 'desc', &block) ⇒ Object
Iterate across all failures with the given options
101 102 103 |
# File 'lib/resque/failure.rb', line 101 def self.each(offset = 0, limit = self.count, queue = nil, class_name = nil, order = 'desc', &block) backend.each(offset, limit, queue, class_name, order, &block) end |
.failure_queue_name(job_queue_name) ⇒ Object
Obtain the failure queue name for a given job queue
71 72 73 74 75 |
# File 'lib/resque/failure.rb', line 71 def self.failure_queue_name(job_queue_name) name = "#{job_queue_name}_failed" Resque.data_store.add_failed_queue(name) name end |
.generate_failure_ids? ⇒ Boolean
Whether failures are given a failure_id when they are built.
Defaults to true. An explicit :failure_id passed to create sets the
failure_id even if automatic generation is disabled.
35 36 37 38 |
# File 'lib/resque/failure.rb', line 35 def generate_failure_ids? return true if @generate_failure_ids.nil? !!@generate_failure_ids end |
.job_queue_name(failure_queue_name) ⇒ Object
Obtain the job queue name for a given failure queue
78 79 80 |
# File 'lib/resque/failure.rb', line 78 def self.job_queue_name(failure_queue_name) failure_queue_name.sub(/_failed$/, '') end |
.queues ⇒ Object
Returns an array of all the failed queues in the system
83 84 85 |
# File 'lib/resque/failure.rb', line 83 def self.queues backend.queues end |
.remove(id, queue = nil) ⇒ Object
125 126 127 |
# File 'lib/resque/failure.rb', line 125 def self.remove(id, queue = nil) backend.remove(id, queue) end |
.remove_queue(queue) ⇒ Object
Removes all failed jobs in a specific queue. Queue name should be a string.
142 143 144 |
# File 'lib/resque/failure.rb', line 142 def self.remove_queue(queue) backend.remove_queue(queue) end |
.requeue(id, queue = nil) ⇒ Object
121 122 123 |
# File 'lib/resque/failure.rb', line 121 def self.requeue(id, queue = nil) backend.requeue(id, queue) end |
.requeue_all ⇒ Object
Requeues all failed jobs
136 137 138 |
# File 'lib/resque/failure.rb', line 136 def self.requeue_all backend.requeue_all end |
.requeue_queue(queue) ⇒ Object
Requeues all failed jobs in a specific queue. Queue name should be a string.
131 132 133 |
# File 'lib/resque/failure.rb', line 131 def self.requeue_queue(queue) backend.requeue_queue(queue) end |
.url ⇒ Object
The string url of the backend's web interface, if any.
106 107 108 |
# File 'lib/resque/failure.rb', line 106 def self.url backend.url end |