Class: LaunchDarkly::DataSystem::PollingDataSourceBuilder

Inherits:
Object
  • Object
show all
Includes:
DataSourceBuilderCommon
Defined in:
lib/ldclient-rb/data_system/polling_data_source_builder.rb

Overview

Builder for a polling data source that communicates with LaunchDarkly’s FDv2 polling endpoint.

This builder can be used with ConfigBuilder#initializers or ConfigBuilder#synchronizers to create custom data system configurations.

The polling data source periodically fetches data from LaunchDarkly. It supports conditional requests via ETags, so subsequent polls after the initial request only transfer data if changes have occurred.

Example

polling = LaunchDarkly::DataSystem.polling_ds_builder
  .poll_interval(60)
  .base_uri("https://custom-endpoint.example.com")

data_system = LaunchDarkly::DataSystem.custom
  .synchronizers([polling])

See Also:

Constant Summary collapse

DEFAULT_BASE_URI =

Returns The default base URI for polling requests.

Returns:

  • (String)

    The default base URI for polling requests

"https://sdk.launchdarkly.com"
DEFAULT_POLL_INTERVAL =

Returns The default polling interval in seconds.

Returns:

  • (Float)

    The default polling interval in seconds

30

Instance Method Summary collapse

Methods included from DataSourceBuilderCommon

#base_uri, #connect_timeout, #read_timeout, #socket_factory

Constructor Details

#initializePollingDataSourceBuilder

Returns a new instance of PollingDataSourceBuilder.



98
99
100
# File 'lib/ldclient-rb/data_system/polling_data_source_builder.rb', line 98

def initialize
  @requester = nil
end

Instance Method Details

#build(sdk_key, config) ⇒ LaunchDarkly::Impl::DataSystem::PollingDataSource

Builds the polling data source with the configured parameters.

This method is called internally by the SDK. You do not need to call it directly; instead, pass the builder to ConfigBuilder#initializers or ConfigBuilder#synchronizers.

Parameters:

Returns:



146
147
148
149
150
# File 'lib/ldclient-rb/data_system/polling_data_source_builder.rb', line 146

def build(sdk_key, config)
  http_opts = build_http_config
  requester = @requester || LaunchDarkly::Impl::DataSystem::HTTPPollingRequester.new(sdk_key, http_opts, config)
  LaunchDarkly::Impl::DataSystem::PollingDataSource.new(@poll_interval || DEFAULT_POLL_INTERVAL, requester, config.logger)
end

#poll_interval(secs) ⇒ PollingDataSourceBuilder

Sets the polling interval in seconds.

This controls how frequently the SDK polls LaunchDarkly for updates. Lower values mean more frequent updates but higher network traffic. The default is DEFAULT_POLL_INTERVAL seconds.

Parameters:

  • secs (Float)

    Polling interval in seconds

Returns:



112
113
114
115
# File 'lib/ldclient-rb/data_system/polling_data_source_builder.rb', line 112

def poll_interval(secs)
  @poll_interval = secs
  self
end

#requester(requester) ⇒ PollingDataSourceBuilder

Sets a custom Requester for this polling data source.

By default, the builder uses an HTTP requester that communicates with LaunchDarkly’s FDv2 polling endpoint. Use this method to provide a custom requester implementation for testing or non-standard environments.

Parameters:

Returns:

See Also:



130
131
132
133
# File 'lib/ldclient-rb/data_system/polling_data_source_builder.rb', line 130

def requester(requester)
  @requester = requester
  self
end