-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy path__init__.py
More file actions
77 lines (59 loc) · 2.4 KB
/
__init__.py
File metadata and controls
77 lines (59 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
This module houses FDv2 types and implementations of synchronizers and
initializers for the datasystem.
All types and implementations in this module are considered internal
and are not part of the public API of the LaunchDarkly Python SDK.
They are subject to change without notice and should not be used directly
by users of the SDK.
You have been warned.
"""
from abc import abstractmethod
from dataclasses import dataclass
from typing import Generator, Iterable, Mapping, Optional, Protocol, Tuple
from ldclient.impl.datasystem.protocolv2 import ChangeSet, Selector
from ldclient.impl.util import _Result
from ldclient.interfaces import DataSourceErrorInfo, DataSourceState
PollingResult = _Result[Tuple[ChangeSet, Mapping], str]
class PollingRequester(Protocol): # pylint: disable=too-few-public-methods
"""
PollingRequester allows PollingDataSource to delegate fetching data to
another component.
This is useful for testing the PollingDataSource without needing to set up
a test HTTP server.
"""
@abstractmethod
def fetch(self, selector: Optional[Selector]) -> PollingResult:
"""
Fetches the data for the given selector.
Returns a Result containing a tuple of ChangeSet and any request headers,
or an error if the data could not be retrieved.
"""
raise NotImplementedError
@dataclass(frozen=True)
class Update:
"""
Update represents the results of a synchronizer's ongoing sync
method.
"""
state: DataSourceState
change_set: Optional[ChangeSet] = None
error: Optional[DataSourceErrorInfo] = None
revert_to_fdv1: bool = False
environment_id: Optional[str] = None
class Synchronizer(Protocol): # pylint: disable=too-few-public-methods
"""
Synchronizer represents a component capable of synchronizing data from an external
data source, such as a streaming or polling API.
It is responsible for yielding Update objects that represent the current state
of the data source, including any changes that have occurred since the last
synchronization.
"""
@abstractmethod
def sync(self) -> Generator[Update, None, None]:
"""
sync should begin the synchronization process for the data source, yielding
Update objects until the connection is closed or an unrecoverable error
occurs.
"""
raise NotImplementedError
__all__: list[str] = []