This repository was archived by the owner on May 5, 2022. It is now read-only.
forked from launchdarkly/python-server-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinterfaces.py
More file actions
132 lines (104 loc) · 3.11 KB
/
Copy pathinterfaces.py
File metadata and controls
132 lines (104 loc) · 3.11 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
from abc import ABCMeta, abstractmethod, abstractproperty
class FeatureStore(object):
"""
Stores and retrieves the state of feature flags
"""
__metaclass__ = ABCMeta
@abstractmethod
def get(self, key):
"""
Gets the data for a feature flag for evaluation
:param key: The feature flag key
:type key: str
:return: The feature flag data
:rtype: dict
"""
@abstractmethod
def all(self):
"""
Returns all feature flags and their data
:rtype: dict[str, dict]
"""
@abstractmethod
def init(self, features):
"""
Initializes the store with a set of feature flags. Meant to be called by the optional StreamProcessor
:param features: The features and their data as provided by LD
:type features: dict[str, dict]
"""
@abstractmethod
def delete(self, key, version):
"""
Marks a feature flag as deleted
:param key: The feature flag key
:type key: str
:param version: The version of the flag to mark as deleted
:type version: str
"""
@abstractmethod
def upsert(self, key, feature):
"""
Inserts a feature flag if its version is newer or missing
:param key: The feature flag
:type key: str
:param feature: The feature information
:type feature: dict
"""
@abstractproperty
def initialized(self):
"""
Returns whether the store has been initialized yet or not
:rtype: bool
"""
class BackgroundOperation(object):
"""
Performs a task in the background
"""
# noinspection PyMethodMayBeStatic
def start(self):
"""
Starts an operation in the background. Should return immediately and not block.
"""
pass
def stop(self):
"""
Stops an operation running in the background. May return before the operation is actually stopped.
"""
pass
# noinspection PyMethodMayBeStatic
def is_alive(self):
"""
Returns whether the operation is alive or not
:rtype: bool
"""
return True
class StreamProcessor(BackgroundOperation):
"""
Populates a store from an external data source
"""
__metaclass__ = ABCMeta
class EventConsumer(BackgroundOperation):
"""
Consumes events from the client and sends them to LaunchDarkly
"""
__metaclass__ = ABCMeta
@abstractmethod
def flush(self):
"""
Flushes any outstanding events immediately.
"""
class FeatureRequester(object):
"""
Requests features if they aren't in the store
"""
__metaclass__ = ABCMeta
@abstractmethod
def get(self, key, callback):
"""
Gets a feature and calls the callback with the feature data to return the result
:param key: The feature key
:type key: str
:param callback: The function that accepts the feature data and returns the feature value
:type callback: function
:return: The feature value. None if not found
"""