Skip to content

Instantly share code, notes, and snippets.

@mcfiredrill
Created April 16, 2013 15:28
Show Gist options
  • Save mcfiredrill/5396883 to your computer and use it in GitHub Desktop.
Save mcfiredrill/5396883 to your computer and use it in GitHub Desktop.
resque's wacky failure backend architecture
module Resque
module Failure
class Base
end
end
end
module Resque
module Failure
@backend = nil
#
# Sets the current backend. Expects a class descendant of
# `Resque::Failure::Base`.
#
# Example use:
# require 'resque/failure/hoptoad'
# Resque::Failure.backend = Resque::Failure::Hoptoad
def self.backend=(backend)
@backend = backend
end
# Returns the current backend class. If none has been set, falls
# back to `Resque::Failure::Redis`
def self.backend
@backend ||= begin
require 'resque/failure/redis'
Failure::Redis
end
end
def self.remove(id)
backend.remove(id)
end
end
end
module Resque
module Failure
# A Failure backend that stores exceptions in Redis. Very simple but
# works out of the box, along with support in the Resque web app.
class RedisMultiQueue < Base
def self.remove(id, queue = :failed)
sentinel = ""
Resque.redis.lset(queue, id, sentinel)
Resque.redis.lrem(queue, 1, sentinel)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment