Class: LaunchDarkly::Impl::DataSystem::PollingDataSource Private
- Inherits:
-
Object
- Object
- LaunchDarkly::Impl::DataSystem::PollingDataSource
- Includes:
- LaunchDarkly::Interfaces::DataSystem::Initializer, LaunchDarkly::Interfaces::DataSystem::Synchronizer
- Defined in:
- lib/ldclient-rb/impl/data_system/polling.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
PollingDataSource is a data source that can retrieve information from LaunchDarkly either as an Initializer or as a Synchronizer.
Instance Attribute Summary collapse
- #name ⇒ Object readonly private
Instance Method Summary collapse
-
#fetch(ss) ⇒ LaunchDarkly::Interfaces::DataSystem::FetchResult
private
Fetch returns a LaunchDarkly::Interfaces::DataSystem::FetchResult wrapping a Basis (or an error) and the FDv1 Fallback Directive signal carried on the server response.
-
#initialize(poll_interval, requester, logger) ⇒ PollingDataSource
constructor
private
A new instance of PollingDataSource.
-
#stop ⇒ Object
private
Stops the synchronizer.
-
#sync(ss) {|update| ... } ⇒ Object
private
sync begins the synchronization process for the data source, yielding Update objects until the connection is closed or an unrecoverable error occurs.
Constructor Details
#initialize(poll_interval, requester, logger) ⇒ PollingDataSource
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PollingDataSource.
93 94 95 96 97 98 99 100 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 93 def initialize(poll_interval, requester, logger) @requester = requester @poll_interval = poll_interval @logger = logger @interrupt_event = Concurrent::Event.new @stop = Concurrent::Event.new @name = "PollingDataSourceV2" end |
Instance Attribute Details
#name ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
86 87 88 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 86 def name @name end |
Instance Method Details
#fetch(ss) ⇒ LaunchDarkly::Interfaces::DataSystem::FetchResult
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Fetch returns a LaunchDarkly::Interfaces::DataSystem::FetchResult wrapping a Basis (or an error) and the FDv1 Fallback Directive signal carried on the server response.
110 111 112 113 114 115 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 110 def fetch(ss) poll(ss) ensure # Ensure the requester is stopped to avoid leaving open connections. @requester.stop if @requester.respond_to?(:stop) end |
#stop ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Stops the synchronizer.
220 221 222 223 224 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 220 def stop @logger.info { "[LDClient] Stopping PollingDataSourceV2 synchronizer" } @interrupt_event.set @stop.set end |
#sync(ss) {|update| ... } ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
sync begins the synchronization process for the data source, yielding Update objects until the connection is closed or an unrecoverable error occurs.
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 125 def sync(ss) @logger.info { "[LDClient] Starting PollingDataSourceV2 synchronizer" } until @stop.set? result = @requester.fetch(ss.selector) fallback = LaunchDarkly::Impl::DataSystem.fdv1_fallback_requested?(result.headers) envid = LaunchDarkly::Impl::DataSystem.lookup_header(result.headers, LD_ENVID_HEADER) if !result.success? if result.exception.is_a?(LaunchDarkly::Impl::DataSource::UnexpectedResponseError) error_info = LaunchDarkly::Interfaces::DataSource::ErrorInfo.new( LaunchDarkly::Interfaces::DataSource::ErrorInfo::ERROR_RESPONSE, result.exception.status, Impl::Util.( result.exception.status, "polling request", "will retry" ), Time.now ) status_code = result.exception.status if Impl::Util.http_error_recoverable?(status_code) # If fallback is requested, send OFF status to signal shutdown if fallback yield LaunchDarkly::Interfaces::DataSystem::Update.new( state: LaunchDarkly::Interfaces::DataSource::Status::OFF, error: error_info, environment_id: envid, fallback_to_fdv1: true ) break end yield LaunchDarkly::Interfaces::DataSystem::Update.new( state: LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED, error: error_info, environment_id: envid, fallback_to_fdv1: false ) @interrupt_event.wait(@poll_interval) next end yield LaunchDarkly::Interfaces::DataSystem::Update.new( state: LaunchDarkly::Interfaces::DataSource::Status::OFF, error: error_info, environment_id: envid, fallback_to_fdv1: fallback ) break end error_info = LaunchDarkly::Interfaces::DataSource::ErrorInfo.new( LaunchDarkly::Interfaces::DataSource::ErrorInfo::NETWORK_ERROR, 0, result.error, Time.now ) # If fallback is requested, send OFF status to signal shutdown if fallback yield LaunchDarkly::Interfaces::DataSystem::Update.new( state: LaunchDarkly::Interfaces::DataSource::Status::OFF, error: error_info, environment_id: envid, fallback_to_fdv1: true ) break end yield LaunchDarkly::Interfaces::DataSystem::Update.new( state: LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED, error: error_info, environment_id: envid, fallback_to_fdv1: false ) else yield LaunchDarkly::Interfaces::DataSystem::Update.new( state: LaunchDarkly::Interfaces::DataSource::Status::VALID, change_set: result.value, environment_id: envid, fallback_to_fdv1: fallback ) end break if fallback break if @interrupt_event.wait(@poll_interval) end ensure # Ensure the requester is stopped to avoid leaving open connections. @requester.stop if @requester.respond_to?(:stop) end |