Class: Tasker::Types::BackoffConfig
- Inherits:
-
BaseConfig
- Object
- Dry::Struct
- BaseConfig
- Tasker::Types::BackoffConfig
- Defined in:
- lib/tasker/types/backoff_config.rb
Overview
Configuration type for retry backoff calculation settings
This configuration exposes previously hardcoded backoff timing constants used in retry logic and exponential backoff calculations.
Instance Attribute Summary collapse
-
#backoff_multiplier ⇒ Float
readonly
Exponential backoff multiplier.
-
#buffer_seconds ⇒ Integer
readonly
Buffer time in seconds.
-
#default_backoff_seconds ⇒ Array<Integer>
readonly
Backoff progression in seconds.
-
#default_reenqueue_delay ⇒ Integer
readonly
Default reenqueue delay in seconds.
-
#jitter_enabled ⇒ Boolean
readonly
Whether jitter is enabled.
-
#jitter_max_percentage ⇒ Float
readonly
Maximum jitter as a decimal percentage.
-
#max_backoff_seconds ⇒ Integer
readonly
Maximum backoff time in seconds.
-
#reenqueue_delays ⇒ Hash
readonly
Mapping of execution status to delay seconds.
Instance Method Summary collapse
-
#calculate_backoff_seconds(attempt_number) ⇒ Integer
Calculate backoff time for a given attempt.
Methods inherited from BaseConfig
Constructor Details
This class inherits a constructor from Tasker::Types::BaseConfig
Instance Attribute Details
#backoff_multiplier ⇒ Float (readonly)
Returns Exponential backoff multiplier.
54 |
# File 'lib/tasker/types/backoff_config.rb', line 54 attribute :backoff_multiplier, Types::Float.default(2.0) |
#buffer_seconds ⇒ Integer (readonly)
Returns Buffer time in seconds.
111 |
# File 'lib/tasker/types/backoff_config.rb', line 111 attribute :buffer_seconds, Types::Integer.default(5) |
#default_backoff_seconds ⇒ Array<Integer> (readonly)
Returns Backoff progression in seconds.
35 36 |
# File 'lib/tasker/types/backoff_config.rb', line 35 attribute :default_backoff_seconds, Types::Array.of(Types::Integer) .default([1, 2, 4, 8, 16, 32].freeze) |
#default_reenqueue_delay ⇒ Integer (readonly)
Returns Default reenqueue delay in seconds.
102 |
# File 'lib/tasker/types/backoff_config.rb', line 102 attribute :default_reenqueue_delay, Types::Integer.default(30) |
#jitter_enabled ⇒ Boolean (readonly)
Returns Whether jitter is enabled.
63 |
# File 'lib/tasker/types/backoff_config.rb', line 63 attribute :jitter_enabled, Types::Bool.default(true) |
#jitter_max_percentage ⇒ Float (readonly)
Returns Maximum jitter as a decimal percentage.
73 |
# File 'lib/tasker/types/backoff_config.rb', line 73 attribute :jitter_max_percentage, Types::Float.default(0.1) |
#max_backoff_seconds ⇒ Integer (readonly)
Returns Maximum backoff time in seconds.
45 |
# File 'lib/tasker/types/backoff_config.rb', line 45 attribute :max_backoff_seconds, Types::Integer.default(300) |
#reenqueue_delays ⇒ Hash (readonly)
Returns Mapping of execution status to delay seconds.
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/tasker/types/backoff_config.rb', line 83 attribute :reenqueue_delays, Types::Hash.schema( has_ready_steps: Types::Integer.default { 0 }, # Steps ready - immediate processing waiting_for_dependencies: Types::Integer.default { 45 }, # Waiting for deps - moderate delay processing: Types::Integer.default { 10 } # Processing - short delay ).constructor { |value| value.respond_to?(:deep_symbolize_keys) ? value.deep_symbolize_keys : value }.default({ has_ready_steps: 0, waiting_for_dependencies: 45, processing: 10 }.freeze) |
Instance Method Details
#calculate_backoff_seconds(attempt_number) ⇒ Integer
Calculate backoff time for a given attempt
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/tasker/types/backoff_config.rb', line 117 def calculate_backoff_seconds(attempt_number) return 0 if attempt_number <= 0 # Use predefined progression if available base_backoff = if attempt_number <= default_backoff_seconds.length default_backoff_seconds[attempt_number - 1] else # Use exponential backoff for attempts beyond predefined progression (attempt_number**backoff_multiplier).to_i end # Apply maximum limit backoff_time = [base_backoff, max_backoff_seconds].min # Apply jitter if enabled if jitter_enabled jitter_range = (backoff_time * jitter_max_percentage).round jitter = Random.rand(-jitter_range..jitter_range) backoff_time = [backoff_time + jitter, 1].max # Ensure minimum 1 second end backoff_time end |