Skip to content

Commit 410a42f

Browse files
eplusminusashanbrown
authored andcommitted
Increase minimum polling interval to 30s and add warning to streaming parameter (#19)
* increase minimum poll interval to 30s * add warning against disabling streaming * add docs for most of the config options
1 parent 02152b3 commit 410a42f

File tree

3 files changed

+44
-8
lines changed

3 files changed

+44
-8
lines changed

ldclient/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ def __init__(self, sdk_key=None, config=None, start_wait=5):
7878
self._update_processor = StreamingUpdateProcessor(
7979
self._config, self._feature_requester, self._store, update_processor_ready)
8080
else:
81+
log.info("Disabling streaming API")
82+
log.warn("You should only disable the streaming API if instructed to do so by LaunchDarkly support")
8183
self._update_processor = PollingUpdateProcessor(
8284
self._config, self._feature_requester, self._store, update_processor_ready)
8385
""" :type: UpdateProcessor """

ldclient/config.py

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def __init__(self,
2222
send_events=None,
2323
events_enabled=True,
2424
update_processor_class=None,
25-
poll_interval=1,
25+
poll_interval=30,
2626
use_ldd=False,
2727
feature_store=InMemoryFeatureStore(),
2828
feature_requester_class=None,
@@ -31,16 +31,47 @@ def __init__(self,
3131
all_attributes_private=False,
3232
offline=False):
3333
"""
34-
35-
:param update_processor_class: A factory for an UpdateProcessor implementation taking the sdk key, config,
36-
and FeatureStore implementation
34+
:param string sdk_key: The SDK key for your LaunchDarkly account.
35+
:param string base_uri: The base URL for the LaunchDarkly server. Most users should use the default
36+
value.
37+
:param string events_uri: The URL for the LaunchDarkly events server. Most users should use the
38+
default value.
39+
:param float connect_timeout: The connect timeout for network connections in seconds.
40+
:param float read_timeout: The read timeout for network connections in seconds.
41+
:param int events_upload_max_batch_size: The maximum number of analytics events that the client will
42+
send at once.
43+
:param int events_max_pending: The capacity of the events buffer. The client buffers up to this many
44+
events in memory before flushing. If the capacity is exceeded before the buffer is flushed, events
45+
will be discarded.
46+
:param string stream_uri: The URL for the LaunchDarkly streaming events server. Most users should
47+
use the default value.
48+
:param bool stream: Whether or not the streaming API should be used to receive flag updates. By
49+
default, it is enabled. Streaming should only be disabled on the advice of LaunchDarkly support.
50+
:param bool send_events: Whether or not to send events back to LaunchDarkly. This differs from
51+
`offline` in that it affects only the sending of client-side events, not streaming or polling for
52+
events from the server. By default, events will be sent.
53+
:param bool events_enabled: Obsolete name for `send_events`.
54+
:param bool offline: Whether the client should be initialized in offline mode. In offline mode,
55+
default values are returned for all flags and no remote network requests are made. By default,
56+
this is false.
3757
:type update_processor_class: (str, Config, FeatureStore) -> UpdateProcessor
58+
:param float poll_interval: The number of seconds between polls for flag updates if streaming is off.
59+
:param bool use_ldd: Whether you are using the LaunchDarkly relay proxy in daemon mode. In this
60+
configuration, the client will not use a streaming connection to listen for updates, but instead
61+
will get feature state from a Redis instance. The `stream` and `poll_interval` options will be
62+
ignored if this option is set to true. By default, this is false.
63+
:param array private_attribute_names: Marks a set of attribute names private. Any users sent to
64+
LaunchDarkly with this configuration active will have attributes with these names removed.
65+
:param bool all_attributes_private: If true, all user attributes (other than the key) will be
66+
private, not just the attributes specified in `private_attribute_names`.
3867
:param feature_store: A FeatureStore implementation
3968
:type feature_store: FeatureStore
4069
:param feature_requester_class: A factory for a FeatureRequester implementation taking the sdk key and config
4170
:type feature_requester_class: (str, Config, FeatureStore) -> FeatureRequester
4271
:param event_consumer_class: A factory for an EventConsumer implementation taking the event queue, sdk key, and config
4372
:type event_consumer_class: (queue.Queue, str, Config) -> EventConsumer
73+
:param update_processor_class: A factory for an UpdateProcessor implementation taking the sdk key,
74+
config, and FeatureStore implementation
4475
"""
4576
self.__sdk_key = sdk_key
4677

@@ -52,9 +83,7 @@ def __init__(self,
5283
self.__stream_uri = stream_uri.rstrip('\\')
5384
self.__update_processor_class = update_processor_class
5485
self.__stream = stream
55-
if poll_interval < 1:
56-
poll_interval = 1
57-
self.__poll_interval = poll_interval
86+
self.__poll_interval = max(poll_interval, 30)
5887
self.__use_ldd = use_ldd
5988
self.__feature_store = InMemoryFeatureStore() if not feature_store else feature_store
6089
self.__event_consumer_class = EventConsumerImpl if not event_consumer_class else event_consumer_class

testing/test_config.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,10 @@ def test_copy_config():
1414
assert new_config.sdk_key is new_sdk_key
1515
assert new_config.stream is False
1616

17+
def test_can_set_valid_poll_interval():
18+
config = Config(sdk_key = "SDK_KEY", poll_interval = 31)
19+
assert config.poll_interval is 31
1720

18-
21+
def test_minimum_poll_interval_is_enforced():
22+
config = Config(sdk_key = "SDK_KEY", poll_interval = 29)
23+
assert config.poll_interval is 30

0 commit comments

Comments
 (0)