Class: Temporalio::RetryPolicy

Inherits:
Struct
  • Object
show all
Defined in:
lib/temporalio/retry_policy.rb

Overview

Options for retrying workflows and activities.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**kwargs) ⇒ RetryPolicy

Returns a new instance of RetryPolicy.



26
27
28
29
30
31
# File 'lib/temporalio/retry_policy.rb', line 26

def initialize(*, **kwargs)
  kwargs[:initial_interval] = 1.0 unless kwargs.key?(:initial_interval)
  kwargs[:backoff_coefficient] = 2.0 unless kwargs.key?(:backoff_coefficient)
  kwargs[:max_attempts] = 0 unless kwargs.key?(:max_attempts)
  super
end

Instance Attribute Details

#backoff_coefficientFloat

Returns Coefficient to multiply previous backoff interval by to get new interval. Default 2.0.

Returns:

  • (Float)

    Coefficient to multiply previous backoff interval by to get new interval. Default 2.0.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/temporalio/retry_policy.rb', line 18

RetryPolicy = Struct.new(
  :initial_interval,
  :backoff_coefficient,
  :max_interval,
  :max_attempts,
  :non_retryable_error_types,
  keyword_init: true
) do
  def initialize(*, **kwargs)
    kwargs[:initial_interval] = 1.0 unless kwargs.key?(:initial_interval)
    kwargs[:backoff_coefficient] = 2.0 unless kwargs.key?(:backoff_coefficient)
    kwargs[:max_attempts] = 0 unless kwargs.key?(:max_attempts)
    super
  end

  # @!visibility private
  def to_proto
    # @type self: RetryPolicy
    raise 'Initial interval cannot be negative' if initial_interval.negative?
    raise 'Backoff coefficient cannot be less than 1' if backoff_coefficient < 1
    raise 'Max interval cannot be negative' if max_interval&.negative?
    raise 'Max interval cannot be less than initial interval' if max_interval && max_interval < initial_interval
    raise 'Max attempts cannot be negative' if max_attempts.negative?

    Api::Common::V1::RetryPolicy.new(
      initial_interval: Internal::ProtoUtils.seconds_to_duration(initial_interval),
      backoff_coefficient:,
      maximum_interval: Internal::ProtoUtils.seconds_to_duration(max_interval),
      maximum_attempts: max_attempts,
      non_retryable_error_types:
    )
  end
end

#initial_intervalFloat

Returns Backoff interval in seconds for the first retry. Default 1.0.

Returns:

  • (Float)

    Backoff interval in seconds for the first retry. Default 1.0.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/temporalio/retry_policy.rb', line 18

RetryPolicy = Struct.new(
  :initial_interval,
  :backoff_coefficient,
  :max_interval,
  :max_attempts,
  :non_retryable_error_types,
  keyword_init: true
) do
  def initialize(*, **kwargs)
    kwargs[:initial_interval] = 1.0 unless kwargs.key?(:initial_interval)
    kwargs[:backoff_coefficient] = 2.0 unless kwargs.key?(:backoff_coefficient)
    kwargs[:max_attempts] = 0 unless kwargs.key?(:max_attempts)
    super
  end

  # @!visibility private
  def to_proto
    # @type self: RetryPolicy
    raise 'Initial interval cannot be negative' if initial_interval.negative?
    raise 'Backoff coefficient cannot be less than 1' if backoff_coefficient < 1
    raise 'Max interval cannot be negative' if max_interval&.negative?
    raise 'Max interval cannot be less than initial interval' if max_interval && max_interval < initial_interval
    raise 'Max attempts cannot be negative' if max_attempts.negative?

    Api::Common::V1::RetryPolicy.new(
      initial_interval: Internal::ProtoUtils.seconds_to_duration(initial_interval),
      backoff_coefficient:,
      maximum_interval: Internal::ProtoUtils.seconds_to_duration(max_interval),
      maximum_attempts: max_attempts,
      non_retryable_error_types:
    )
  end
end

#max_attemptsInteger

Returns Maximum number of attempts. If ‘0`, the default, there is no maximum.

Returns:

  • (Integer)

    Maximum number of attempts. If ‘0`, the default, there is no maximum.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/temporalio/retry_policy.rb', line 18

RetryPolicy = Struct.new(
  :initial_interval,
  :backoff_coefficient,
  :max_interval,
  :max_attempts,
  :non_retryable_error_types,
  keyword_init: true
) do
  def initialize(*, **kwargs)
    kwargs[:initial_interval] = 1.0 unless kwargs.key?(:initial_interval)
    kwargs[:backoff_coefficient] = 2.0 unless kwargs.key?(:backoff_coefficient)
    kwargs[:max_attempts] = 0 unless kwargs.key?(:max_attempts)
    super
  end

  # @!visibility private
  def to_proto
    # @type self: RetryPolicy
    raise 'Initial interval cannot be negative' if initial_interval.negative?
    raise 'Backoff coefficient cannot be less than 1' if backoff_coefficient < 1
    raise 'Max interval cannot be negative' if max_interval&.negative?
    raise 'Max interval cannot be less than initial interval' if max_interval && max_interval < initial_interval
    raise 'Max attempts cannot be negative' if max_attempts.negative?

    Api::Common::V1::RetryPolicy.new(
      initial_interval: Internal::ProtoUtils.seconds_to_duration(initial_interval),
      backoff_coefficient:,
      maximum_interval: Internal::ProtoUtils.seconds_to_duration(max_interval),
      maximum_attempts: max_attempts,
      non_retryable_error_types:
    )
  end
end

#max_intervalFloat?

Returns Maximum backoff interval in seconds between retries. Default 100x ‘initial_interval`.

Returns:

  • (Float, nil)

    Maximum backoff interval in seconds between retries. Default 100x ‘initial_interval`.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/temporalio/retry_policy.rb', line 18

RetryPolicy = Struct.new(
  :initial_interval,
  :backoff_coefficient,
  :max_interval,
  :max_attempts,
  :non_retryable_error_types,
  keyword_init: true
) do
  def initialize(*, **kwargs)
    kwargs[:initial_interval] = 1.0 unless kwargs.key?(:initial_interval)
    kwargs[:backoff_coefficient] = 2.0 unless kwargs.key?(:backoff_coefficient)
    kwargs[:max_attempts] = 0 unless kwargs.key?(:max_attempts)
    super
  end

  # @!visibility private
  def to_proto
    # @type self: RetryPolicy
    raise 'Initial interval cannot be negative' if initial_interval.negative?
    raise 'Backoff coefficient cannot be less than 1' if backoff_coefficient < 1
    raise 'Max interval cannot be negative' if max_interval&.negative?
    raise 'Max interval cannot be less than initial interval' if max_interval && max_interval < initial_interval
    raise 'Max attempts cannot be negative' if max_attempts.negative?

    Api::Common::V1::RetryPolicy.new(
      initial_interval: Internal::ProtoUtils.seconds_to_duration(initial_interval),
      backoff_coefficient:,
      maximum_interval: Internal::ProtoUtils.seconds_to_duration(max_interval),
      maximum_attempts: max_attempts,
      non_retryable_error_types:
    )
  end
end

#non_retryable_error_typesArray<String>?

Returns List of error types that are not retryable.

Returns:

  • (Array<String>, nil)

    List of error types that are not retryable.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/temporalio/retry_policy.rb', line 18

RetryPolicy = Struct.new(
  :initial_interval,
  :backoff_coefficient,
  :max_interval,
  :max_attempts,
  :non_retryable_error_types,
  keyword_init: true
) do
  def initialize(*, **kwargs)
    kwargs[:initial_interval] = 1.0 unless kwargs.key?(:initial_interval)
    kwargs[:backoff_coefficient] = 2.0 unless kwargs.key?(:backoff_coefficient)
    kwargs[:max_attempts] = 0 unless kwargs.key?(:max_attempts)
    super
  end

  # @!visibility private
  def to_proto
    # @type self: RetryPolicy
    raise 'Initial interval cannot be negative' if initial_interval.negative?
    raise 'Backoff coefficient cannot be less than 1' if backoff_coefficient < 1
    raise 'Max interval cannot be negative' if max_interval&.negative?
    raise 'Max interval cannot be less than initial interval' if max_interval && max_interval < initial_interval
    raise 'Max attempts cannot be negative' if max_attempts.negative?

    Api::Common::V1::RetryPolicy.new(
      initial_interval: Internal::ProtoUtils.seconds_to_duration(initial_interval),
      backoff_coefficient:,
      maximum_interval: Internal::ProtoUtils.seconds_to_duration(max_interval),
      maximum_attempts: max_attempts,
      non_retryable_error_types:
    )
  end
end