-
Notifications
You must be signed in to change notification settings - Fork 45
chore: Create datasystem and related protocols #346
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+747
−125
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
efe0351
chore: Create datasystem and related protocols
keelerm84 f9a276f
Fix shared list initialization
keelerm84 a2808c5
revert automated formatting changes
keelerm84 4a7947f
trailing newlines
keelerm84 1d67096
Add type
keelerm84 05f82fd
Fix whitespace
keelerm84 ec1ec86
fix doc
keelerm84 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,12 +8,13 @@ | |
| from collections import namedtuple | ||
| from threading import Event | ||
| from time import time | ||
| from typing import Generator, Optional, Protocol | ||
| from typing import Generator, Mapping, Optional, Protocol, Tuple | ||
| from urllib import parse | ||
|
|
||
| import urllib3 | ||
|
|
||
| from ldclient.impl.datasourcev2 import BasisResult, PollingResult, Update | ||
| from ldclient.config import Config | ||
| from ldclient.impl.datasystem import BasisResult, Update | ||
| from ldclient.impl.datasystem.protocolv2 import ( | ||
| Basis, | ||
| ChangeSet, | ||
|
|
@@ -46,7 +47,7 @@ | |
| POLLING_ENDPOINT = "/sdk/poll" | ||
|
|
||
|
|
||
| CacheEntry = namedtuple("CacheEntry", ["data", "etag"]) | ||
| PollingResult = _Result[Tuple[ChangeSet, Mapping], str] | ||
|
|
||
|
|
||
| class Requester(Protocol): # pylint: disable=too-few-public-methods | ||
|
|
@@ -68,6 +69,9 @@ def fetch(self, selector: Optional[Selector]) -> PollingResult: | |
| raise NotImplementedError | ||
|
|
||
|
|
||
| CacheEntry = namedtuple("CacheEntry", ["data", "etag"]) | ||
|
|
||
|
|
||
| class PollingDataSource: | ||
| """ | ||
| PollingDataSource is a data source that can retrieve information from | ||
|
|
@@ -206,7 +210,7 @@ class Urllib3PollingRequester: | |
| requests. | ||
| """ | ||
|
|
||
| def __init__(self, config): | ||
| def __init__(self, config: Config): | ||
| self._etag = None | ||
| self._http = _http_factory(config).create_pool_manager(1, config.base_uri) | ||
| self._config = config | ||
|
|
@@ -335,3 +339,30 @@ def polling_payload_to_changeset(data: dict) -> _Result[ChangeSet, str]: | |
| ) | ||
|
|
||
| return _Fail(error="didn't receive any known protocol events in polling payload") | ||
|
|
||
|
|
||
| class PollingDataSourceBuilder: | ||
| """ | ||
| Builder for a PollingDataSource. | ||
| """ | ||
|
|
||
| def __init__(self, config: Config): | ||
| self._config = config | ||
| self._requester: Optional[Requester] = None | ||
|
|
||
| def requester(self, requester: Requester) -> "PollingDataSourceBuilder": | ||
| """Sets a custom Requester for the PollingDataSource.""" | ||
| self._requester = requester | ||
| return self | ||
|
|
||
| def build(self) -> PollingDataSource: | ||
| """Builds the PollingDataSource with the configured parameters.""" | ||
| requester = ( | ||
| self._requester | ||
| if self._requester is not None | ||
| else Urllib3PollingRequester(self._config) | ||
| ) | ||
|
|
||
| return PollingDataSource( | ||
| poll_interval=self._config.poll_interval, requester=requester | ||
| ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bug: Polling Config Mismatch Causes SDK Startup Failure
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These types are more generally a part of the data system, so we should move them there.