Class: Springcm::Middleware::RetryConnectionFailed
- Inherits:
-
Object
- Object
- Springcm::Middleware::RetryConnectionFailed
- Defined in:
- lib/springcm-sdk/middleware/retry_connection_failed.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = { retries: 5 }) ⇒ RetryConnectionFailed
constructor
A new instance of RetryConnectionFailed.
Constructor Details
#initialize(app, options = { retries: 5 }) ⇒ RetryConnectionFailed
Returns a new instance of RetryConnectionFailed.
6 7 8 9 |
# File 'lib/springcm-sdk/middleware/retry_connection_failed.rb', line 6 def initialize(app, ={ retries: 5 }) @app = app @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/springcm-sdk/middleware/retry_connection_failed.rb', line 4 def @options end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/springcm-sdk/middleware/retry_connection_failed.rb', line 11 def call(env) retries = @options[:retries] delay = 1 begin @app.call(env).on_complete do |response_env| end rescue Faraday::ConnectionFailed => err if retries > 0 retries -= 1 sleep delay delay *= 2 retry else raise err end end end |