Class: ComplyanceSDK::Config::RetryConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/complyance_sdk/config/retry_config.rb

Overview

Configuration for retry behavior

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ RetryConfig

Initialize a new retry configuration

Parameters:

  • options (Hash) (defaults to: {})

    Configuration options

Options Hash (options):

  • :max_attempts (Integer)

    Maximum number of retry attempts

  • :base_delay (Float)

    Base delay between retries in seconds

  • :max_delay (Float)

    Maximum delay between retries in seconds

  • :backoff_multiplier (Float)

    Backoff multiplier for exponential backoff

  • :jitter_factor (Float)

    Jitter factor to add randomness to retry delays

  • :circuit_breaker_enabled (Boolean)

    Whether circuit breaker is enabled

  • :failure_threshold (Integer)

    Failure threshold for circuit breaker

  • :circuit_breaker_timeout (Float)

    Circuit breaker timeout in seconds

  • :retryable_http_codes (Array<Integer>)

    HTTP status codes that should trigger a retry



49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/complyance_sdk/config/retry_config.rb', line 49

def initialize(options = {})
  @max_attempts = options.fetch(:max_attempts, 3)
  @base_delay = options.fetch(:base_delay, 1000) # Base delay in milliseconds to match Java
  @max_delay = options.fetch(:max_delay, 30000) # Max delay in milliseconds to match Java
  @backoff_multiplier = options.fetch(:backoff_multiplier, 2.0)
  @jitter_factor = options.fetch(:jitter_factor, 0.2)
  @circuit_breaker_enabled = options.fetch(:circuit_breaker_enabled, true)
  @failure_threshold = options.fetch(:failure_threshold, 5)
  @circuit_breaker_timeout = options.fetch(:circuit_breaker_timeout, 60.0)
  @retryable_http_codes = options.fetch(:retryable_http_codes, [408, 429, 500, 502, 503, 504])
  @retryable_error_codes = options.fetch(:retryable_error_codes, [:network_error, :timeout_error, :rate_limited, :temporary_error])
end

Instance Attribute Details

#backoff_multiplierObject

Backoff multiplier for exponential backoff



17
18
19
# File 'lib/complyance_sdk/config/retry_config.rb', line 17

def backoff_multiplier
  @backoff_multiplier
end

#base_delayObject

Base delay between retries in seconds



11
12
13
# File 'lib/complyance_sdk/config/retry_config.rb', line 11

def base_delay
  @base_delay
end

#circuit_breaker_enabledObject

Whether circuit breaker is enabled



23
24
25
# File 'lib/complyance_sdk/config/retry_config.rb', line 23

def circuit_breaker_enabled
  @circuit_breaker_enabled
end

#circuit_breaker_timeoutObject

Circuit breaker timeout in seconds



29
30
31
# File 'lib/complyance_sdk/config/retry_config.rb', line 29

def circuit_breaker_timeout
  @circuit_breaker_timeout
end

#failure_thresholdObject

Failure threshold for circuit breaker



26
27
28
# File 'lib/complyance_sdk/config/retry_config.rb', line 26

def failure_threshold
  @failure_threshold
end

#jitter_factorObject

Jitter factor to add randomness to retry delays



20
21
22
# File 'lib/complyance_sdk/config/retry_config.rb', line 20

def jitter_factor
  @jitter_factor
end

#max_attemptsObject

Maximum number of retry attempts



8
9
10
# File 'lib/complyance_sdk/config/retry_config.rb', line 8

def max_attempts
  @max_attempts
end

#max_delayObject

Maximum delay between retries in seconds



14
15
16
# File 'lib/complyance_sdk/config/retry_config.rb', line 14

def max_delay
  @max_delay
end

#retryable_error_codesObject

Error codes that should trigger a retry



35
36
37
# File 'lib/complyance_sdk/config/retry_config.rb', line 35

def retryable_error_codes
  @retryable_error_codes
end

#retryable_http_codesObject

HTTP status codes that should trigger a retry



32
33
34
# File 'lib/complyance_sdk/config/retry_config.rb', line 32

def retryable_http_codes
  @retryable_http_codes
end

Class Method Details

.aggressiveRetryConfig

Create an aggressive retry configuration

Returns:



72
73
74
75
76
77
78
79
80
81
# File 'lib/complyance_sdk/config/retry_config.rb', line 72

def self.aggressive
  new(
    max_attempts: 7,
    base_delay: 0.2,
    max_delay: 10.0,
    backoff_multiplier: 1.5,
    jitter_factor: 0.1,
    circuit_breaker_timeout: 30.0
  )
end

.conservativeRetryConfig

Create a conservative retry configuration

Returns:



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/complyance_sdk/config/retry_config.rb', line 86

def self.conservative
  new(
    max_attempts: 3,
    base_delay: 2.0,
    max_delay: 60.0,
    backoff_multiplier: 3.0,
    jitter_factor: 0.3,
    failure_threshold: 3,
    circuit_breaker_timeout: 120.0
  )
end

.defaultRetryConfig

Create a default retry configuration

Returns:



65
66
67
# File 'lib/complyance_sdk/config/retry_config.rb', line 65

def self.default
  new
end

.noneRetryConfig

Create a retry configuration with no retries

Returns:

  • (RetryConfig)

    A retry configuration with no retries



101
102
103
104
105
106
# File 'lib/complyance_sdk/config/retry_config.rb', line 101

def self.none
  new(
    max_attempts: 1,
    circuit_breaker_enabled: false
  )
end

Instance Method Details

#circuit_breaker_configHash

Get circuit breaker configuration

Returns:

  • (Hash)

    Circuit breaker configuration hash



111
112
113
114
115
116
117
# File 'lib/complyance_sdk/config/retry_config.rb', line 111

def circuit_breaker_config
  {
    failure_threshold: @failure_threshold,
    timeout_seconds: @circuit_breaker_timeout.to_i,
    success_threshold: 1
  }
end

#circuit_breaker_enabled?Boolean

Check if circuit breaker is enabled

Returns:

  • (Boolean)

    True if circuit breaker is enabled



122
123
124
# File 'lib/complyance_sdk/config/retry_config.rb', line 122

def circuit_breaker_enabled?
  @circuit_breaker_enabled
end