Class: JobWorkflow::TaskRetry
- Inherits:
-
Object
- Object
- JobWorkflow::TaskRetry
- Defined in:
- lib/job_workflow/task_retry.rb
Instance Attribute Summary collapse
-
#base_delay ⇒ Object
readonly
: Integer.
-
#count ⇒ Object
readonly
: Integer.
-
#jitter ⇒ Object
readonly
: bool.
-
#strategy ⇒ Object
readonly
: Symbol.
Class Method Summary collapse
-
.from_primitive_value(value) ⇒ Object
: (Integer | Hash[Symbol, untyped]) -> TaskRetry.
Instance Method Summary collapse
-
#delay_for(retry_attempt) ⇒ Object
: (Integer) -> Float.
-
#initialize(count: 0, strategy: :exponential, base_delay: 1, jitter: false) ⇒ TaskRetry
constructor
: (?count: Integer, ?strategy: Symbol, ?base_delay: Integer, ?jitter: bool) -> void.
Constructor Details
#initialize(count: 0, strategy: :exponential, base_delay: 1, jitter: false) ⇒ TaskRetry
: (?count: Integer, ?strategy: Symbol, ?base_delay: Integer, ?jitter: bool) -> void
30 31 32 33 34 35 |
# File 'lib/job_workflow/task_retry.rb', line 30 def initialize(count: 0, strategy: :exponential, base_delay: 1, jitter: false) @count = count @strategy = strategy @base_delay = base_delay @jitter = jitter end |
Instance Attribute Details
#base_delay ⇒ Object (readonly)
: Integer
7 8 9 |
# File 'lib/job_workflow/task_retry.rb', line 7 def base_delay @base_delay end |
#count ⇒ Object (readonly)
: Integer
5 6 7 |
# File 'lib/job_workflow/task_retry.rb', line 5 def count @count end |
#jitter ⇒ Object (readonly)
: bool
8 9 10 |
# File 'lib/job_workflow/task_retry.rb', line 8 def jitter @jitter end |
#strategy ⇒ Object (readonly)
: Symbol
6 7 8 |
# File 'lib/job_workflow/task_retry.rb', line 6 def strategy @strategy end |
Class Method Details
.from_primitive_value(value) ⇒ Object
: (Integer | Hash[Symbol, untyped]) -> TaskRetry
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/job_workflow/task_retry.rb', line 12 def from_primitive_value(value) case value when Integer new(count: value) when Hash new( count: value.fetch(:count, 3), strategy: value.fetch(:strategy, :exponential), base_delay: value.fetch(:base_delay, 1), jitter: value.fetch(:jitter, false) ) else raise ArgumentError, "retry must be Integer or Hash" end end |
Instance Method Details
#delay_for(retry_attempt) ⇒ Object
: (Integer) -> Float
38 39 40 41 |
# File 'lib/job_workflow/task_retry.rb', line 38 def delay_for(retry_attempt) delay = calculate_base_delay(retry_attempt) apply_jitter(delay) end |