module Resque::Failure

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.

Public Class Methods

all(offset = 0, limit = 1, queue = nil) click to toggle source

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.

# File lib/resque/failure.rb, line 74
def self.all(offset = 0, limit = 1, queue = nil)
  backend.all(offset, limit, queue)
end
backend() click to toggle source

Returns the current backend class. If none has been set, falls back to `Resque::Failure::Redis`

# File lib/resque/failure.rb, line 33
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) click to toggle source

Sets the current backend. Expects a class descendent of `Resque::Failure::Base`.

Example use:

require 'resque/failure/airbrake'
Resque::Failure.backend = Resque::Failure::Airbrake
# File lib/resque/failure.rb, line 27
def self.backend=(backend)
  @backend = backend
end
clear(queue = nil) click to toggle source

Clear all failure jobs

# File lib/resque/failure.rb, line 89
def self.clear(queue = nil)
  backend.clear(queue)
end
count(queue = nil, class_name = nil) click to toggle source

Returns the int count of how many failures we have seen.

# File lib/resque/failure.rb, line 66
def self.count(queue = nil, class_name = nil)
  backend.count(queue, class_name)
end
create(options = {}) click to toggle source

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
# File lib/resque/failure.rb, line 16
def self.create(options = {})
  backend.new(*options.values_at(:exception, :worker, :queue, :payload)).save
end
each(offset = 0, limit = self.count, queue = nil, class_name = nil, order = 'desc', &block) click to toggle source

Iterate across all failures with the given options

# File lib/resque/failure.rb, line 79
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) click to toggle source

Obtain the failure queue name for a given job queue

# File lib/resque/failure.rb, line 49
def self.failure_queue_name(job_queue_name)
  name = "#{job_queue_name}_failed"
  Resque.redis.sadd(:failed_queues, name)
  name
end
job_queue_name(failure_queue_name) click to toggle source

Obtain the job queue name for a given failure queue

# File lib/resque/failure.rb, line 56
def self.job_queue_name(failure_queue_name)
  failure_queue_name.sub(/_failed$/, '')
end
queues() click to toggle source

Returns an array of all the failed queues in the system

# File lib/resque/failure.rb, line 61
def self.queues
  backend.queues
end
remove(id) click to toggle source
# File lib/resque/failure.rb, line 97
def self.remove(id)
  backend.remove(id)
end
remove_queue(queue) click to toggle source

Removes all failed jobs in a specific queue. Queue name should be a string.

# File lib/resque/failure.rb, line 109
def self.remove_queue(queue)
  backend.remove_queue(queue)
end
requeue(id) click to toggle source
# File lib/resque/failure.rb, line 93
def self.requeue(id)
  backend.requeue(id)
end
requeue_queue(queue) click to toggle source

Requeues all failed jobs in a specific queue. Queue name should be a string.

# File lib/resque/failure.rb, line 103
def self.requeue_queue(queue)
  backend.requeue_queue(queue)
end
url() click to toggle source

The string url of the backend's web interface, if any.

# File lib/resque/failure.rb, line 84
def self.url
  backend.url
end