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

Constructor Details

#initializePollingDataSourceBuilder

Returns a new instance of PollingDataSourceBuilder.



96
97
98
# File 'lib/ldclient-rb/data_system/polling_data_source_builder.rb', line 96

def initialize
  @requester = nil
end

Instance Method Details

#base_uri(uri) ⇒ self Originally defined in module DataSourceBuilderCommon

Sets the base URI for HTTP requests.

Use this to point the SDK at a Relay Proxy instance or any other URI that implements the corresponding LaunchDarkly API.

Parameters:

Returns:

  • (self)

    the builder, for chaining

#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:

  • (LaunchDarkly::Impl::DataSystem::PollingDataSource)


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

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

#connect_timeout(timeout) ⇒ self Originally defined in module DataSourceBuilderCommon

Sets the connect timeout for HTTP connections.

Parameters:

  • timeout (Float)

    Timeout in seconds

Returns:

  • (self)

    the builder, for chaining

#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:



110
111
112
113
# File 'lib/ldclient-rb/data_system/polling_data_source_builder.rb', line 110

def poll_interval(secs)
  @poll_interval = secs
  self
end

#read_timeout(timeout) ⇒ self Originally defined in module DataSourceBuilderCommon

Sets the read timeout for HTTP connections.

Parameters:

  • timeout (Float)

    Timeout in seconds

Returns:

  • (self)

    the builder, for chaining

#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:



128
129
130
131
# File 'lib/ldclient-rb/data_system/polling_data_source_builder.rb', line 128

def requester(requester)
  @requester = requester
  self
end

#socket_factory(factory) ⇒ self Originally defined in module DataSourceBuilderCommon

Sets a custom socket factory for HTTP connections.

Parameters:

  • factory (#open)

    A socket factory that responds to +open+

Returns:

  • (self)

    the builder, for chaining