Class: CldProvisioning::Utils::RetryConfig
- Inherits:
-
Object
- Object
- CldProvisioning::Utils::RetryConfig
- Extended by:
- T::Sig
- Defined in:
- lib/cld_provisioning/utils/retries.rb
Instance Attribute Summary collapse
-
#backoff ⇒ Object
Returns the value of attribute backoff.
-
#retry_connection_errors ⇒ Object
Returns the value of attribute retry_connection_errors.
-
#strategy ⇒ Object
Returns the value of attribute strategy.
Instance Method Summary collapse
-
#initialize(backoff: nil, retry_connection_errors: nil, strategy: nil) ⇒ RetryConfig
constructor
A new instance of RetryConfig.
- #to_faraday_retry_options(initial_time:) ⇒ Object
Constructor Details
#initialize(backoff: nil, retry_connection_errors: nil, strategy: nil) ⇒ RetryConfig
Returns a new instance of RetryConfig.
64 65 66 67 68 |
# File 'lib/cld_provisioning/utils/retries.rb', line 64 def initialize(backoff: nil, retry_connection_errors: nil, strategy: nil) @backoff = T.let(backoff, T.nilable(BackoffStrategy)) @retry_connection_errors = T.let(retry_connection_errors, T.nilable(T::Boolean)) @strategy = T.let(strategy, T.nilable(::String)) end |
Instance Attribute Details
#backoff ⇒ Object
Returns the value of attribute backoff.
48 49 50 |
# File 'lib/cld_provisioning/utils/retries.rb', line 48 def backoff @backoff end |
#retry_connection_errors ⇒ Object
Returns the value of attribute retry_connection_errors.
51 52 53 |
# File 'lib/cld_provisioning/utils/retries.rb', line 51 def retry_connection_errors @retry_connection_errors end |
#strategy ⇒ Object
Returns the value of attribute strategy.
54 55 56 |
# File 'lib/cld_provisioning/utils/retries.rb', line 54 def strategy @strategy end |
Instance Method Details
#to_faraday_retry_options(initial_time:) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/cld_provisioning/utils/retries.rb', line 71 def (initial_time:) = { # must overwrite default max of 2 retries and it must be positive max: 1_000_000_000, # ensure all HTTP methods are retried, especially via retry_if methods: [] } if @retry_connection_errors [:exceptions] = Faraday::Retry::Middleware::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed] end if @strategy == "backoff" && @backoff [:backoff_factor] = @backoff.exponent unless @backoff.exponent.nil? [:interval] = (@backoff.initial_interval.to_f / 1000) unless @backoff.initial_interval.nil? [:max_interval] = @backoff.max_interval unless @backoff.max_interval.nil? unless @backoff.max_elapsed_time.nil? stop_time = initial_time + (@backoff.max_elapsed_time.to_f / 1000) [:retry_if] = -> (_env, _exc) { Time.now < stop_time } end end end |