Class: Temporalio::RetryPolicy
- Inherits:
-
Object
- Object
- Temporalio::RetryPolicy
- Defined in:
- lib/temporalio/retry_policy.rb
Overview
Options for retrying workflows and activities.
Defined Under Namespace
Classes: Invalid
Instance Attribute Summary collapse
-
#backoff ⇒ Float
readonly
Coefficient to multiply previous backoff interval by to get new interval.
-
#initial_interval ⇒ Integer
readonly
Backoff interval for the first retry.
-
#max_attempts ⇒ Integer
readonly
Maximum number of attempts.
-
#max_interval ⇒ Integer?
readonly
Maximum backoff interval between retries.
-
#non_retriable_errors ⇒ Array<String>
readonly
List of error types that are not retryable.
Instance Method Summary collapse
-
#initialize(initial_interval: 1, backoff: 2.0, max_interval: nil, max_attempts: 0, non_retriable_errors: []) ⇒ RetryPolicy
constructor
A new instance of RetryPolicy.
- #to_proto ⇒ Object
- #validate! ⇒ Object
Constructor Details
#initialize(initial_interval: 1, backoff: 2.0, max_interval: nil, max_attempts: 0, non_retriable_errors: []) ⇒ RetryPolicy
Returns a new instance of RetryPolicy.
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/temporalio/retry_policy.rb', line 34 def initialize( initial_interval: 1, backoff: 2.0, max_interval: nil, max_attempts: 0, non_retriable_errors: [] ) @initial_interval = initial_interval @backoff = backoff @max_interval = max_interval @max_attempts = max_attempts @non_retriable_errors = non_retriable_errors end |
Instance Attribute Details
#backoff ⇒ Float (readonly)
Returns Coefficient to multiply previous backoff interval by to get new interval.
15 16 17 |
# File 'lib/temporalio/retry_policy.rb', line 15 def backoff @backoff end |
#initial_interval ⇒ Integer (readonly)
Returns Backoff interval for the first retry.
12 13 14 |
# File 'lib/temporalio/retry_policy.rb', line 12 def initial_interval @initial_interval end |
#max_attempts ⇒ Integer (readonly)
Returns Maximum number of attempts. If 0, the default, there is no maximum.
22 23 24 |
# File 'lib/temporalio/retry_policy.rb', line 22 def max_attempts @max_attempts end |
#max_interval ⇒ Integer? (readonly)
Returns Maximum backoff interval between retries. Default 100x #initial_interval.
19 20 21 |
# File 'lib/temporalio/retry_policy.rb', line 19 def max_interval @max_interval end |
#non_retriable_errors ⇒ Array<String> (readonly)
Returns List of error types that are not retryable.
25 26 27 |
# File 'lib/temporalio/retry_policy.rb', line 25 def non_retriable_errors @non_retriable_errors end |
Instance Method Details
#to_proto ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'lib/temporalio/retry_policy.rb', line 72 def to_proto Temporalio::Api::Common::V1::RetryPolicy.new( initial_interval: Google::Protobuf::Duration.new(seconds: initial_interval), backoff_coefficient: backoff, maximum_interval: max_interval ? Google::Protobuf::Duration.new(seconds: max_interval) : nil, maximum_attempts: max_attempts, non_retryable_error_types: non_retriable_errors.map(&:name).compact, ) end |
#validate! ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/temporalio/retry_policy.rb', line 48 def validate! # Retries disabled return if max_attempts == 1 # Maximum attempts raise Invalid, 'Maximum attempts must be specified' unless max_attempts raise Invalid, 'Maximum attempts cannot be negative' if max_attempts.negative? # Initial interval raise Invalid, 'Initial interval must be specified' unless initial_interval raise Invalid, 'Initial interval cannot be negative' if initial_interval.negative? raise Invalid, 'Initial interval must be in whole seconds' unless initial_interval.is_a?(Integer) # Backoff coefficient raise Invalid, 'Backoff coefficient must be specified' unless backoff raise Invalid, 'Backoff coefficient cannot be less than 1' if backoff < 1 # Maximum interval if max_interval raise Invalid, 'Maximum interval cannot be negative' if max_interval.negative? raise Invalid, 'Maximum interval cannot be less than initial interval' if max_interval < initial_interval end end |