Class: ChronoMachines::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/chrono_machines/configuration.rb

Constant Summary collapse

DEFAULT_POLICY_NAME =
:default

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/chrono_machines/configuration.rb', line 9

def initialize
  @policies = {
    DEFAULT_POLICY_NAME => {
      max_attempts: 3,
      base_delay: 0.1, # seconds
      multiplier: 2,
      max_delay: 10, # seconds
      jitter_factor: 0.1, # 10% jitter (though full jitter makes this less direct)
      retryable_exceptions: [StandardError],
      on_failure: nil, # Fallback block when all retries are exhausted
      on_retry: nil,   # Callback block when a retry occurs
      on_success: nil  # Callback block when operation succeeds
    }
  }
end

Instance Attribute Details

#policiesObject (readonly)

Returns the value of attribute policies.



7
8
9
# File 'lib/chrono_machines/configuration.rb', line 7

def policies
  @policies
end

Instance Method Details

#define_policy(name, options) ⇒ Object



25
26
27
# File 'lib/chrono_machines/configuration.rb', line 25

def define_policy(name, options)
  @policies[name.to_sym] = @policies[DEFAULT_POLICY_NAME].merge(options)
end

#get_policy(name) ⇒ Object



29
30
31
# File 'lib/chrono_machines/configuration.rb', line 29

def get_policy(name)
  @policies[name.to_sym] || raise(ArgumentError, "Policy '#{name}' not found.")
end