1616 StreamingDataSourceBuilder
1717)
1818from ldclient .impl .datasystem import Initializer , Synchronizer
19+ from ldclient .interfaces import DataStoreMode , FeatureStore
1920
2021T = TypeVar ("T" )
2122
@@ -30,6 +31,8 @@ class ConfigBuilder: # pylint: disable=too-few-public-methods
3031 _initializers : Optional [List [Builder [Initializer ]]] = None
3132 _primary_synchronizer : Optional [Builder [Synchronizer ]] = None
3233 _secondary_synchronizer : Optional [Builder [Synchronizer ]] = None
34+ _store_mode : DataStoreMode = DataStoreMode .READ_ONLY
35+ _data_store : Optional [FeatureStore ] = None
3336
3437 def initializers (self , initializers : Optional [List [Builder [Initializer ]]]) -> "ConfigBuilder" :
3538 """
@@ -50,17 +53,27 @@ def synchronizers(
5053 self ._secondary_synchronizer = secondary
5154 return self
5255
56+ def data_store (self , data_store : FeatureStore , store_mode : DataStoreMode ) -> "ConfigBuilder" :
57+ """
58+ Sets the data store configuration for the data system.
59+ """
60+ self ._data_store = data_store
61+ self ._store_mode = store_mode
62+ return self
63+
5364 def build (self ) -> DataSystemConfig :
5465 """
5566 Builds the data system configuration.
5667 """
57- if self ._primary_synchronizer is None :
58- raise ValueError ("Primary synchronizer must be set" )
68+ if self ._secondary_synchronizer is not None and self . _primary_synchronizer is None :
69+ raise ValueError ("Primary synchronizer must be set if secondary is set " )
5970
6071 return DataSystemConfig (
6172 initializers = self ._initializers ,
6273 primary_synchronizer = self ._primary_synchronizer ,
6374 secondary_synchronizer = self ._secondary_synchronizer ,
75+ data_store_mode = self ._store_mode ,
76+ data_store = self ._data_store ,
6477 )
6578
6679
@@ -147,18 +160,29 @@ def custom() -> ConfigBuilder:
147160 return ConfigBuilder ()
148161
149162
150- # TODO(fdv2): Implement these methods
151- #
152- # Daemon configures the SDK to read from a persistent store integration
153- # that is populated by Relay Proxy or other SDKs. The SDK will not connect
154- # to LaunchDarkly. In this mode, the SDK never writes to the data store.
163+ # TODO(fdv2): Need to update these so they don't rely on the LDConfig
164+ def daemon (config : LDConfig , store : FeatureStore ) -> ConfigBuilder :
165+ """
166+ Daemon configures the SDK to read from a persistent store integration
167+ that is populated by Relay Proxy or other SDKs. The SDK will not connect
168+ to LaunchDarkly. In this mode, the SDK never writes to the data store.
169+ """
170+ return default (config ).data_store (store , DataStoreMode .READ_ONLY )
171+
155172
156- # PersistentStore is similar to Default, with the addition of a persistent
157- # store integration. Before data has arrived from LaunchDarkly, the SDK is
158- # able to evaluate flags using data from the persistent store. Once fresh
159- # data is available, the SDK will no longer read from the persistent store,
160- # although it will keep it up-to-date.
173+ def persistent_store (config : LDConfig , store : FeatureStore ) -> ConfigBuilder :
174+ """
175+ PersistentStore is similar to Default, with the addition of a persistent
176+ store integration. Before data has arrived from LaunchDarkly, the SDK is
177+ able to evaluate flags using data from the persistent store. Once fresh
178+ data is available, the SDK will no longer read from the persistent store,
179+ although it will keep it up-to-date.
180+ """
181+ return default (config ).data_store (store , DataStoreMode .READ_WRITE )
161182
183+
184+ # TODO(fdv2): Implement these methods
185+ #
162186# WithEndpoints configures the data system with custom endpoints for
163187# LaunchDarkly's streaming and polling synchronizers. This method is not
164188# necessary for most use-cases, but can be useful for testing or custom
0 commit comments