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.
Class Method Summary collapse
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.
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/temporalio/retry_policy.rb', line 44 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.map(&:to_s).compact 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 |
Class Method Details
.from_proto(proto) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/temporalio/retry_policy.rb', line 27 def self.from_proto(proto) new( initial_interval: proto.initial_interval&.to_f&.round || 0, backoff: proto.backoff_coefficient&.to_f || 0.0, max_interval: proto.maximum_interval&.to_f&.round || 0, max_attempts: proto.maximum_attempts || 1, non_retriable_errors: proto.non_retryable_error_types || [], ).freeze end |
Instance Method Details
#to_proto ⇒ Object
82 83 84 85 86 87 88 89 90 |
# File 'lib/temporalio/retry_policy.rb', line 82 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, ) end |
#validate! ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/temporalio/retry_policy.rb', line 58 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 |