Skip to content

Commit

Permalink
Throw our own ConnectionError.
Browse files Browse the repository at this point in the history
Instead of bubbling up the Redis error, we want to throw our own.

Also wrote documentation that is better for the reconnect method.
  • Loading branch information
prsimp authored and steveklabnik committed Apr 17, 2013
1 parent d202456 commit 5319ef2
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions lib/resque/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,25 @@
# one project.
module Resque
class Client

# This error is thrown if we have a problem connecting to
# the back end.
ConnectionError = Class.new(StandardError)

attr_reader :backend, :logger

def initialize(backend, logger)
@backend = backend
@logger = logger
end

# Reconnect to Redis to avoid sharing a connection with the parent,
# retry up to 3 times with increasing delay before giving up.
# Reconnects to the backend
#
# Maybe your backend died, maybe you've just forked. Whatever the
# reason, this method will attempt to reconnect to the backend.
#
# If it can't connect, it will attempt to rety the connection after
# sleeping, and after 3 failures will throw an exception.
def reconnect
tries = 0
begin
Expand All @@ -30,7 +40,7 @@ def reconnect

if tries == 3
logger.info "Error reconnecting to Redis; quitting"
raise
raise ConnectionError
end

logger.info "Error reconnecting to Redis; retrying"
Expand Down

0 comments on commit 5319ef2

Please sign in to comment.