FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-client/splitio/push/processor.py at development · splitio/python-client · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
splitio
/
python-client
Public
Notifications
You must be signed in to change notification settings
Fork
13
Star
19
Code
Issues
4
Pull requests
6
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-client
/
splitio
/
push
/
processor.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
192 lines (155 loc) · 6.95 KB
Breadcrumbs
python-client
/
splitio
/
push
/
processor.py
Copy path
File metadata and controls
192 lines (155 loc) · 6.95 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
"""Message processor & Notification manager keeper implementations."""
from
queue
import
Queue
import
abc
from
splitio
.
push
.
parser
import
UpdateType
from
splitio
.
push
.
workers
import
SplitWorker
,
SplitWorkerAsync
,
SegmentWorker
,
SegmentWorkerAsync
from
splitio
.
optional
.
loaders
import
asyncio
class
MessageProcessorBase
(
object
,
metaclass
=
abc
.
ABCMeta
):
"""Message processor template."""
@
abc
.
abstractmethod
def
update_workers_status
(
self
,
enabled
):
"""Enable/Disable push update workers."""
@
abc
.
abstractmethod
def
handle
(
self
,
event
):
"""Handle incoming update event."""
@
abc
.
abstractmethod
def
shutdown
(
self
):
"""Stop splits & segments workers."""
class
MessageProcessor
(
MessageProcessorBase
):
"""Message processor class."""
def
__init__
(
self
,
synchronizer
,
telemetry_runtime_producer
):
"""
Class constructor.
:param synchronizer: synchronizer component
:type synchronizer: splitio.sync.synchronizer.Synchronizer
"""
self
.
_feature_flag_queue
=
Queue
()
self
.
_segments_queue
=
Queue
()
self
.
_synchronizer
=
synchronizer
self
.
_feature_flag_worker
=
SplitWorker
(
synchronizer
.
synchronize_splits
,
synchronizer
.
synchronize_segment
,
self
.
_feature_flag_queue
,
synchronizer
.
split_sync
.
feature_flag_storage
,
synchronizer
.
segment_storage
,
telemetry_runtime_producer
,
synchronizer
.
split_sync
.
rule_based_segment_storage
)
self
.
_segments_worker
=
SegmentWorker
(
synchronizer
.
synchronize_segment
,
self
.
_segments_queue
)
self
.
_handlers
=
{
UpdateType
.
SPLIT_UPDATE
:
self
.
_handle_feature_flag_update
,
UpdateType
.
SPLIT_KILL
:
self
.
_handle_feature_flag_kill
,
UpdateType
.
SEGMENT_UPDATE
:
self
.
_handle_segment_change
,
UpdateType
.
RB_SEGMENT_UPDATE
:
self
.
_handle_feature_flag_update
}
def
_handle_feature_flag_update
(
self
,
event
):
"""
Handle incoming feature_flag update notification.
:param event: Incoming feature_flag change event
:type event: splitio.push.parser.SplitChangeUpdate
"""
self
.
_feature_flag_queue
.
put
(
event
)
def
_handle_feature_flag_kill
(
self
,
event
):
"""
Handle incoming feature flag kill notification.
:param event: Incoming feature flag kill event
:type event: splitio.push.parser.SplitKillUpdate
"""
self
.
_synchronizer
.
kill_split
(
event
.
feature_flag_name
,
event
.
default_treatment
,
event
.
change_number
)
self
.
_feature_flag_queue
.
put
(
event
)
def
_handle_segment_change
(
self
,
event
):
"""
Handle incoming segment update notification.
:param event: Incoming segment change event
:type event: splitio.push.parser.Update
"""
self
.
_segments_queue
.
put
(
event
)
def
update_workers_status
(
self
,
enabled
):
"""
Enable/Disable push update workers.
:param enabled: if True, enable workers. If False, disable them.
:type enabled: bool
"""
if
enabled
:
self
.
_feature_flag_worker
.
start
()
self
.
_segments_worker
.
start
()
else
:
self
.
_feature_flag_worker
.
stop
()
self
.
_segments_worker
.
stop
()
def
handle
(
self
,
event
):
"""
Handle incoming update event.
:param event: incoming data update event.
:type event: splitio.push.BaseUpdate
"""
try
:
handle
=
self
.
_handlers
[
event
.
update_type
]
except
KeyError
as
exc
:
raise
Exception
(
'no handler for notification type: %s'
%
event
.
update_type
)
from
exc
handle
(
event
)
def
shutdown
(
self
):
"""Stop feature flags & segments workers."""
self
.
_feature_flag_worker
.
stop
()
self
.
_segments_worker
.
stop
()
class
MessageProcessorAsync
(
MessageProcessorBase
):
"""Message processor class."""
def
__init__
(
self
,
synchronizer
,
telemetry_runtime_producer
):
"""
Class constructor.
:param synchronizer: synchronizer component
:type synchronizer: splitio.sync.synchronizer.Synchronizer
"""
self
.
_feature_flag_queue
=
asyncio
.
Queue
()
self
.
_segments_queue
=
asyncio
.
Queue
()
self
.
_synchronizer
=
synchronizer
self
.
_feature_flag_worker
=
SplitWorkerAsync
(
synchronizer
.
synchronize_splits
,
synchronizer
.
synchronize_segment
,
self
.
_feature_flag_queue
,
synchronizer
.
split_sync
.
feature_flag_storage
,
synchronizer
.
segment_storage
,
telemetry_runtime_producer
,
synchronizer
.
split_sync
.
rule_based_segment_storage
)
self
.
_segments_worker
=
SegmentWorkerAsync
(
synchronizer
.
synchronize_segment
,
self
.
_segments_queue
)
self
.
_handlers
=
{
UpdateType
.
SPLIT_UPDATE
:
self
.
_handle_feature_flag_update
,
UpdateType
.
SPLIT_KILL
:
self
.
_handle_feature_flag_kill
,
UpdateType
.
SEGMENT_UPDATE
:
self
.
_handle_segment_change
,
UpdateType
.
RB_SEGMENT_UPDATE
:
self
.
_handle_feature_flag_update
}
async
def
_handle_feature_flag_update
(
self
,
event
):
"""
Handle incoming feature_flag update notification.
:param event: Incoming feature_flag change event
:type event: splitio.push.parser.SplitChangeUpdate
"""
await
self
.
_feature_flag_queue
.
put
(
event
)
async
def
_handle_feature_flag_kill
(
self
,
event
):
"""
Handle incoming feature_flag kill notification.
:param event: Incoming feature_flag kill event
:type event: splitio.push.parser.SplitKillUpdate
"""
await
self
.
_synchronizer
.
kill_split
(
event
.
feature_flag_name
,
event
.
default_treatment
,
event
.
change_number
)
await
self
.
_feature_flag_queue
.
put
(
event
)
async
def
_handle_segment_change
(
self
,
event
):
"""
Handle incoming segment update notification.
:param event: Incoming segment change event
:type event: splitio.push.parser.Update
"""
await
self
.
_segments_queue
.
put
(
event
)
async
def
update_workers_status
(
self
,
enabled
):
"""
Enable/Disable push update workers.
:param enabled: if True, enable workers. If False, disable them.
:type enabled: bool
"""
if
enabled
:
self
.
_feature_flag_worker
.
start
()
self
.
_segments_worker
.
start
()
else
:
await
self
.
_feature_flag_worker
.
stop
()
await
self
.
_segments_worker
.
stop
()
async
def
handle
(
self
,
event
):
"""
Handle incoming update event.
:param event: incoming data update event.
:type event: splitio.push.BaseUpdate
"""
try
:
handle
=
self
.
_handlers
[
event
.
update_type
]
except
KeyError
as
exc
:
raise
Exception
(
'no handler for notification type: %s'
%
event
.
update_type
)
from
exc
await
handle
(
event
)
async
def
shutdown
(
self
):
"""Stop splits & segments workers."""
await
self
.
_feature_flag_worker
.
stop
()
await
self
.
_segments_worker
.
stop
()
Back
|
FazBrowse Home
|
New Git URL