Permalink
Browse files

Do not try to reconnect to beanstalk servers until all of the connect…

…ions have failed
  • Loading branch information...
1 parent c0d80a8 commit 2fbf670a85081e9d7f74176793f18fdeea715fef @jbaudanza committed Nov 2, 2011
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/beanstalk-client/connection.rb
View
12 lib/beanstalk-client/connection.rb
@@ -273,6 +273,10 @@ def connect()
@connections.size
end
+ def reconnect
+ connect if @connections.empty?
+ end
+
def open_connections()
@connections.values()
end
@@ -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

0 comments on commit 2fbf670

Please sign in to comment.