Class: IbmAppconfigurationRubySdk::BackgroundRetryManager
- Inherits:
-
Object
- Object
- IbmAppconfigurationRubySdk::BackgroundRetryManager
- Defined in:
- lib/ibm_appconfiguration_ruby_sdk/background_retry_manager.rb
Instance Attribute Summary collapse
-
#active ⇒ Object
readonly
Returns the value of attribute active.
-
#attempt ⇒ Object
readonly
Returns the value of attribute attempt.
Instance Method Summary collapse
-
#active? ⇒ Boolean
Check if retry is currently active.
-
#current_attempt ⇒ Integer
Get current attempt number.
-
#initialize(collection_id:, environment_id:, handler:, logger: nil) ⇒ BackgroundRetryManager
constructor
Initialize the retry manager.
-
#start(reason:) ⇒ Boolean
Start the background retry loop.
-
#stop ⇒ Object
Stop the background retry loop.
Constructor Details
#initialize(collection_id:, environment_id:, handler:, logger: nil) ⇒ BackgroundRetryManager
Initialize the retry manager
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ibm_appconfiguration_ruby_sdk/background_retry_manager.rb', line 50 def initialize(collection_id:, environment_id:, handler:, logger: nil) @collection_id = collection_id @environment_id = environment_id @handler = handler @logger = logger || Logger.instance # Initialize ConfigFetcher @config_fetcher = ConfigFetcher.new( collection_id: collection_id, environment_id: environment_id, handler: @handler, logger: @logger ) # State management @active = false @attempt = 0 @cap_ms = nil # Thread management @retry_thread = nil @mutex = Mutex.new end |
Instance Attribute Details
#active ⇒ Object (readonly)
Returns the value of attribute active.
42 43 44 |
# File 'lib/ibm_appconfiguration_ruby_sdk/background_retry_manager.rb', line 42 def active @active end |
#attempt ⇒ Object (readonly)
Returns the value of attribute attempt.
42 43 44 |
# File 'lib/ibm_appconfiguration_ruby_sdk/background_retry_manager.rb', line 42 def attempt @attempt end |
Instance Method Details
#active? ⇒ Boolean
Check if retry is currently active
139 140 141 |
# File 'lib/ibm_appconfiguration_ruby_sdk/background_retry_manager.rb', line 139 def active? @mutex.synchronize { @active } end |
#current_attempt ⇒ Integer
Get current attempt number
146 147 148 |
# File 'lib/ibm_appconfiguration_ruby_sdk/background_retry_manager.rb', line 146 def current_attempt @mutex.synchronize { @attempt } end |
#start(reason:) ⇒ Boolean
Start the background retry loop
This method:
- Checks if retry is already active (prevents duplicate retries)
- Initializes retry state (attempt counter, cap delay)
- Schedules the first retry attempt
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/ibm_appconfiguration_ruby_sdk/background_retry_manager.rb', line 84 def start(reason:) # Thread-safe check and initialization should_start = false @mutex.synchronize do if @active @logger.info("Background retry already active (attempt ##{@attempt}). Reason: #{reason}") return false end # Initialize retry state @active = true @attempt = 0 @cap_ms = compute_cap_delay_ms should_start = true end if should_start cap_hours = (@cap_ms / 3_600_000.0).round(2) @logger.info("Starting background retry (cap #{cap_hours} hours). Reason: #{reason}") schedule_next_attempt(reason) end true end |
#stop ⇒ Object
Stop the background retry loop
This method:
- Sets active flag to false (stops scheduling new attempts)
- Kills the current retry thread if running
- Resets all state variables
Thread-safe and idempotent (safe to call multiple times)
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/ibm_appconfiguration_ruby_sdk/background_retry_manager.rb', line 118 def stop @mutex.synchronize do return unless @active @active = false @attempt = 0 @cap_ms = nil end # Kill retry thread outside mutex to avoid deadlock if @retry_thread&.alive? @retry_thread.kill @retry_thread = nil end @logger.info(Constants::BACKGROUND_RETRY_STOPPED) end |