Skip to content

Commit

Permalink
Do not try to reconnect to beanstalk servers until all of the connect…
Browse files Browse the repository at this point in the history
…ions have failed
  • Loading branch information
jbaudanza committed Nov 2, 2011
1 parent c0d80a8 commit 2fbf670
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions lib/beanstalk-client/connection.rb
Expand Up @@ -273,6 +273,10 @@ def connect()
@connections.size
end

def reconnect
connect if @connections.empty?
end

def open_connections()
@connections.values()
end
Expand Down Expand Up @@ -405,22 +409,22 @@ def retry_wrap(*args)
# Don't reconnect -- we're not interested in this server
retry
rescue EOFError, Errno::ECONNRESET, Errno::EPIPE
connect()
reconnect()
retry
end

def send_to_each_conn_first_res(*args)
connect()
reconnect
retry_wrap{open_connections.inject(nil) {|r,c| r or call_wrap(c, *args)}}
end

def send_to_rand_conn(*args, &block)
connect()
reconnect
retry_wrap{call_wrap(pick_connection, *args, &block)}
end

def send_to_all_conns(*args)
connect()
reconnect
retry_wrap{compact_hash(map_hash(@connections){|c| call_wrap(c, *args)})}
end

Expand Down

0 comments on commit 2fbf670

Please sign in to comment.