Class: GraphAgent::RetryPolicy
- Inherits:
-
Object
- Object
- GraphAgent::RetryPolicy
- Defined in:
- lib/graph_agent/types/retry_policy.rb
Instance Attribute Summary collapse
-
#backoff_factor ⇒ Object
readonly
Returns the value of attribute backoff_factor.
-
#initial_interval ⇒ Object
readonly
Returns the value of attribute initial_interval.
-
#jitter ⇒ Object
readonly
Returns the value of attribute jitter.
-
#max_attempts ⇒ Object
readonly
Returns the value of attribute max_attempts.
-
#max_interval ⇒ Object
readonly
Returns the value of attribute max_interval.
-
#retry_on ⇒ Object
readonly
Returns the value of attribute retry_on.
Instance Method Summary collapse
-
#initialize(initial_interval: 0.5, backoff_factor: 2.0, max_interval: 128.0, max_attempts: 3, jitter: true, retry_on: StandardError) ⇒ RetryPolicy
constructor
A new instance of RetryPolicy.
- #interval_for(attempt) ⇒ Object
- #should_retry?(error) ⇒ Boolean
Constructor Details
#initialize(initial_interval: 0.5, backoff_factor: 2.0, max_interval: 128.0, max_attempts: 3, jitter: true, retry_on: StandardError) ⇒ RetryPolicy
Returns a new instance of RetryPolicy.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/graph_agent/types/retry_policy.rb', line 8 def initialize( initial_interval: 0.5, backoff_factor: 2.0, max_interval: 128.0, max_attempts: 3, jitter: true, retry_on: StandardError ) @initial_interval = initial_interval @backoff_factor = backoff_factor @max_interval = max_interval @max_attempts = max_attempts @jitter = jitter @retry_on = retry_on end |
Instance Attribute Details
#backoff_factor ⇒ Object (readonly)
Returns the value of attribute backoff_factor.
5 6 7 |
# File 'lib/graph_agent/types/retry_policy.rb', line 5 def backoff_factor @backoff_factor end |
#initial_interval ⇒ Object (readonly)
Returns the value of attribute initial_interval.
5 6 7 |
# File 'lib/graph_agent/types/retry_policy.rb', line 5 def initial_interval @initial_interval end |
#jitter ⇒ Object (readonly)
Returns the value of attribute jitter.
5 6 7 |
# File 'lib/graph_agent/types/retry_policy.rb', line 5 def jitter @jitter end |
#max_attempts ⇒ Object (readonly)
Returns the value of attribute max_attempts.
5 6 7 |
# File 'lib/graph_agent/types/retry_policy.rb', line 5 def max_attempts @max_attempts end |
#max_interval ⇒ Object (readonly)
Returns the value of attribute max_interval.
5 6 7 |
# File 'lib/graph_agent/types/retry_policy.rb', line 5 def max_interval @max_interval end |
#retry_on ⇒ Object (readonly)
Returns the value of attribute retry_on.
5 6 7 |
# File 'lib/graph_agent/types/retry_policy.rb', line 5 def retry_on @retry_on end |
Instance Method Details
#interval_for(attempt) ⇒ Object
35 36 37 38 39 40 |
# File 'lib/graph_agent/types/retry_policy.rb', line 35 def interval_for(attempt) interval = @initial_interval * (@backoff_factor**attempt) interval = [interval, @max_interval].min interval += rand * interval * 0.1 if @jitter interval end |
#should_retry?(error) ⇒ Boolean
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/graph_agent/types/retry_policy.rb', line 24 def should_retry?(error) case @retry_on when Proc @retry_on.call(error) when Array @retry_on.any? { |klass| error.is_a?(klass) } else error.is_a?(@retry_on) end end |