Skip to content

Commit

Permalink
Small refactoring on Client#reconnect
Browse files Browse the repository at this point in the history
1. We don't need to check if we've already reconnected to reconnect, the redis gem handles that case
2. Let's not increment + test on the same line
3. if/else becomes if for simplicity
  • Loading branch information
prsimp authored and steveklabnik committed Apr 17, 2013
1 parent 6d21210 commit bcd6076
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions lib/resque/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,25 @@ class Client

def initialize(backend)
@backend = backend

@reconnected = false
end

# Reconnect to Redis to avoid sharing a connection with the parent,
# retry up to 3 times with increasing delay before giving up.
def reconnect
return if @reconnected

tries = 0
begin
backend.client.reconnect
@reconnected = true
rescue Redis::BaseConnectionError
if (tries += 1) <= 3
Resque.logger.info "Error reconnecting to Redis; retrying"
sleep(tries)
retry
else
tries += 1

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

Resque.logger.info "Error reconnecting to Redis; retrying"
sleep(tries)
retry
end
end
end
Expand Down

0 comments on commit bcd6076

Please sign in to comment.