Class: ChronoMachines::Configuration
- Inherits:
-
Object
- Object
- ChronoMachines::Configuration
- Defined in:
- lib/chrono_machines/configuration.rb
Constant Summary collapse
- DEFAULT_POLICY_NAME =
:default
Instance Attribute Summary collapse
-
#engine_override ⇒ Object
Returns the value of attribute engine_override.
-
#policies ⇒ Object
readonly
Returns the value of attribute policies.
Instance Method Summary collapse
- #define_policy(name, options) ⇒ Object
- #get_policy(name) ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/chrono_machines/configuration.rb', line 10 def initialize @engine_override = nil # nil = auto-detect, :ruby = force Ruby, :native = force native @policies = { DEFAULT_POLICY_NAME => { backoff_strategy: :exponential, # :exponential, :constant, or :fibonacci max_attempts: 3, base_delay: 0.1, # seconds multiplier: 2, # For exponential backoff max_delay: 10, # seconds jitter_factor: 1.0, # 1.0 = full jitter (recommended), 0.0 = no jitter 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
#engine_override ⇒ Object
Returns the value of attribute engine_override.
8 9 10 |
# File 'lib/chrono_machines/configuration.rb', line 8 def engine_override @engine_override end |
#policies ⇒ Object (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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/chrono_machines/configuration.rb', line 28 def define_policy(name, ) # Deep copy the default policy to avoid shared mutable references default_copy = @policies[DEFAULT_POLICY_NAME].transform_values do |value| case value when Array value.dup when Proc value # Procs are immutable, no need to dup else value # Primitives (numbers, symbols, nil) are immutable end end @policies[name.to_sym] = default_copy.merge() end |
#get_policy(name) ⇒ Object
44 45 46 |
# File 'lib/chrono_machines/configuration.rb', line 44 def get_policy(name) @policies[name.to_sym] || raise(ArgumentError, "Policy '#{name}' not found.") end |