Class: XRBP::WebClient::Plugins::AutoRetry
- Inherits:
-
PluginBase
- Object
- PluginBase
- XRBP::WebClient::Plugins::AutoRetry
- Defined in:
- lib/xrbp/webclient/plugins/autoretry.rb
Overview
Plugin to automatically retry WebClient Connection requests multiple times.
If no max_tries are specified, requests will be tried indefinitely. Optionally configured interval to wait between retries.
Instance Attribute Summary collapse
-
#interval ⇒ Object
Returns the value of attribute interval.
-
#max_tries ⇒ Object
Returns the value of attribute max_tries.
Attributes inherited from PluginBase
Instance Method Summary collapse
- #added ⇒ Object
- #handle_error ⇒ Object
-
#initialize(connection) ⇒ AutoRetry
constructor
A new instance of AutoRetry.
Constructor Details
#initialize(connection) ⇒ AutoRetry
Returns a new instance of AutoRetry.
23 24 25 26 27 28 |
# File 'lib/xrbp/webclient/plugins/autoretry.rb', line 23 def initialize(connection) super(connection) @interval = 3 @max_tries = nil @retry_num = 0 end |
Instance Attribute Details
#interval ⇒ Object
Returns the value of attribute interval.
21 22 23 |
# File 'lib/xrbp/webclient/plugins/autoretry.rb', line 21 def interval @interval end |
#max_tries ⇒ Object
Returns the value of attribute max_tries.
21 22 23 |
# File 'lib/xrbp/webclient/plugins/autoretry.rb', line 21 def max_tries @max_tries end |
Instance Method Details
#added ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xrbp/webclient/plugins/autoretry.rb', line 30 def added plugin = self connection.define_instance_method(:retry_interval=) do |i| plugin.interval = i end connection.define_instance_method(:max_retries=) do |i| plugin.max_tries = i end end |
#handle_error ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/xrbp/webclient/plugins/autoretry.rb', line 41 def handle_error @retry_num += 1 return nil if connection.force_quit? || (!@max_tries.nil? && @retry_num > @max_tries) connection.rsleep(@interval) connection.perform end |