Created
April 16, 2013 15:28
-
-
Save mcfiredrill/5396883 to your computer and use it in GitHub Desktop.
resque's wacky failure backend architecture
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Resque | |
module Failure | |
class Base | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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