Class: ClientProxy
- Inherits:
-
Object
- Object
- ClientProxy
- Defined in:
- lib/client_proxy.rb
Instance Method Summary collapse
- #attempt(try, method, *args, &block) ⇒ Object
-
#initialize(client_factory, hosts, recoverable_errors, max_retries, randomize_order = true) ⇒ ClientProxy
constructor
A new instance of ClientProxy.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(client_factory, hosts, recoverable_errors, max_retries, randomize_order = true) ⇒ ClientProxy
Returns a new instance of ClientProxy.
2 3 4 5 6 7 8 |
# File 'lib/client_proxy.rb', line 2 def initialize(client_factory, hosts, recoverable_errors, max_retries, randomize_order = true) @client_factory = client_factory @hosts = hosts @recoverable_errors = recoverable_errors @max_retries = max_retries @host_pointer = randomize_order ? rand(hosts.length) : -1 end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
10 11 12 |
# File 'lib/client_proxy.rb', line 10 def method_missing(method, *args, &block) attempt(0, method, *args, &block) end |
Instance Method Details
#attempt(try, method, *args, &block) ⇒ Object
14 15 16 17 18 19 20 21 22 |
# File 'lib/client_proxy.rb', line 14 def attempt(try, method, *args, &block) begin current_client.__send__(method, *args, &block) rescue *@recoverable_errors => e @current_client = nil raise e if try == (@max_retries - 1) attempt(try + 1, method, *args, &block) end end |