Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Making retry count customisable #19

Open
wants to merge 1 commit into from

1 participant

Paul Bellamy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 14, 2013
  1. Paul Bellamy
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 4 deletions.
  1. +4 −3 lib/em-jack/connection.rb
  2. +9 −1 spec/em-jack/connection_spec.rb
7 lib/em-jack/connection.rb
View
@@ -6,8 +6,6 @@ module EMJack
class Connection
include EM::Deferrable
- RETRY_COUNT = 5
-
@@handlers = []
attr_accessor :host, :port
@@ -27,6 +25,7 @@ def initialize(opts = {})
@host = opts[:host] || 'localhost'
@port = opts[:port] || 11300
@tube = opts[:tube]
+ @max_retries = opts[:retries]
when String
uri = URI.parse(opts)
@host = uri.host || 'localhost'
@@ -34,6 +33,8 @@ def initialize(opts = {})
@tube = uri.path.gsub(/^\//, '') # Kill the leading /
end
+ @max_retries ||= 5
+
reset_tube_state
@data = ""
@@ -284,7 +285,7 @@ def disconnected
set_deferred_status(nil)
d.each { |df| df.fail(:disconnected) }
- if @retries >= RETRY_COUNT
+ if @retries >= @max_retries
if @disconnected_callback
@disconnected_callback.call
else
10 spec/em-jack/connection_spec.rb
View
@@ -392,13 +392,21 @@
conn.disconnected
end
- it 'raises exception if it fails more then RETRY_COUNT times' do
+ it 'raises exception if it fails more then 5 times' do
EM.should_receive(:add_timer).exactly(5).times
5.times { conn.disconnected }
lambda { conn.disconnected }.should raise_error(EMJack::Disconnected)
end
+ it 'raises exception if it fails more than a custom retry count' do
+ conn = EMJack::Connection.new(:retries => 2)
+ EM.should_receive(:add_timer).exactly(2).times
+
+ 2.times { conn.disconnected }
+ lambda { conn.disconnected }.should raise_error(EMJack::Disconnected)
+ end
+
it 'resets the retry count on connection' do
EM.should_receive(:add_timer).at_least(1).times
Something went wrong with that request. Please try again.