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::Basis?
private
Fetch returns a Basis, or an error if the Basis could not be retrieved.
-
#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.
64 65 66 67 68 69 70 71 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 64 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.
57 58 59 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 57 def name @name end |
Instance Method Details
#fetch(ss) ⇒ LaunchDarkly::Interfaces::DataSystem::Basis?
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 Basis, or an error if the Basis could not be retrieved.
79 80 81 82 83 84 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 79 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.
199 200 201 202 203 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 199 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.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 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 |
# File 'lib/ldclient-rb/impl/data_system/polling.rb', line 94 def sync(ss) @logger.info { "[LDClient] Starting PollingDataSourceV2 synchronizer" } @stop.reset @interrupt_event.reset until @stop.set? result = @requester.fetch(ss.selector) if !result.success? fallback = false envid = nil if result.headers fallback = result.headers[LD_FD_FALLBACK_HEADER] == 'true' envid = result.headers[LD_ENVID_HEADER] end 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, revert_to_fdv1: true ) break end yield LaunchDarkly::Interfaces::DataSystem::Update.new( state: LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED, error: error_info, environment_id: envid, revert_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, revert_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, revert_to_fdv1: true ) break end yield LaunchDarkly::Interfaces::DataSystem::Update.new( state: LaunchDarkly::Interfaces::DataSource::Status::INTERRUPTED, error: error_info, environment_id: envid, revert_to_fdv1: false ) else change_set, headers = result.value fallback = headers[LD_FD_FALLBACK_HEADER] == 'true' yield LaunchDarkly::Interfaces::DataSystem::Update.new( state: LaunchDarkly::Interfaces::DataSource::Status::VALID, change_set: change_set, environment_id: headers[LD_ENVID_HEADER], revert_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 |