5
5
from typing import Awaitable , Callable , List , Optional , Protocol , Union
6
6
7
7
from redis .maintenance_events import (
8
- MaintenanceEvent ,
9
- NodeFailedOverEvent ,
10
- NodeFailingOverEvent ,
11
- NodeMigratedEvent ,
12
- NodeMigratingEvent ,
13
- NodeMovingEvent ,
8
+ MaintenanceNotification ,
9
+ NodeFailedOverNotification ,
10
+ NodeFailingOverNotification ,
11
+ NodeMigratedNotification ,
12
+ NodeMigratingNotification ,
13
+ NodeMovingNotification ,
14
14
)
15
15
16
16
if sys .version_info .major >= 3 and sys .version_info .minor >= 11 :
@@ -175,14 +175,14 @@ class MaintenanceNotificationsParser:
175
175
176
176
@staticmethod
177
177
def parse_maintenance_start_msg (response , notification_type ):
178
- # Expected message format is: <event_type > <seq_number> <time>
178
+ # Expected message format is: <notification_type > <seq_number> <time>
179
179
id = response [1 ]
180
180
ttl = response [2 ]
181
181
return notification_type (id , ttl )
182
182
183
183
@staticmethod
184
184
def parse_maintenance_completed_msg (response , notification_type ):
185
- # Expected message format is: <event_type > <seq_number>
185
+ # Expected message format is: <notification_type > <seq_number>
186
186
id = response [1 ]
187
187
return notification_type (id )
188
188
@@ -200,7 +200,7 @@ def parse_moving_msg(response):
200
200
host , port = value .split (":" )
201
201
port = int (port ) if port is not None else None
202
202
203
- return NodeMovingEvent (id , host , port , ttl )
203
+ return NodeMovingNotification (id , host , port , ttl )
204
204
205
205
206
206
_INVALIDATION_MESSAGE = "invalidate"
@@ -217,25 +217,27 @@ def parse_moving_msg(response):
217
217
_FAILED_OVER_MESSAGE ,
218
218
)
219
219
220
- MSG_TYPE_TO_EVENT_PARSER_MAPPING : dict [str , tuple [type [MaintenanceEvent ], Callable ]] = {
220
+ MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING : dict [
221
+ str , tuple [type [MaintenanceNotification ], Callable ]
222
+ ] = {
221
223
_MIGRATING_MESSAGE : (
222
- NodeMigratingEvent ,
224
+ NodeMigratingNotification ,
223
225
MaintenanceNotificationsParser .parse_maintenance_start_msg ,
224
226
),
225
227
_MIGRATED_MESSAGE : (
226
- NodeMigratedEvent ,
228
+ NodeMigratedNotification ,
227
229
MaintenanceNotificationsParser .parse_maintenance_completed_msg ,
228
230
),
229
231
_FAILING_OVER_MESSAGE : (
230
- NodeFailingOverEvent ,
232
+ NodeFailingOverNotification ,
231
233
MaintenanceNotificationsParser .parse_maintenance_start_msg ,
232
234
),
233
235
_FAILED_OVER_MESSAGE : (
234
- NodeFailedOverEvent ,
236
+ NodeFailedOverNotification ,
235
237
MaintenanceNotificationsParser .parse_maintenance_completed_msg ,
236
238
),
237
239
_MOVING_MESSAGE : (
238
- NodeMovingEvent ,
240
+ NodeMovingNotification ,
239
241
MaintenanceNotificationsParser .parse_moving_msg ,
240
242
),
241
243
}
@@ -273,14 +275,20 @@ def handle_push_response(self, response, **kwargs):
273
275
return self .invalidation_push_handler_func (response )
274
276
275
277
if msg_type == _MOVING_MESSAGE and self .node_moving_push_handler_func :
276
- parser_function = MSG_TYPE_TO_EVENT_PARSER_MAPPING [msg_type ][1 ]
278
+ parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
279
+ msg_type
280
+ ][1 ]
277
281
278
282
notification = parser_function (response )
279
283
return self .node_moving_push_handler_func (notification )
280
284
281
285
if msg_type in _MAINTENANCE_MESSAGES and self .maintenance_push_handler_func :
282
- parser_function = MSG_TYPE_TO_EVENT_PARSER_MAPPING [msg_type ][1 ]
283
- notification_type = MSG_TYPE_TO_EVENT_PARSER_MAPPING [msg_type ][0 ]
286
+ parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
287
+ msg_type
288
+ ][1 ]
289
+ notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
290
+ msg_type
291
+ ][0 ]
284
292
notification = parser_function (response , notification_type )
285
293
286
294
if notification is not None :
@@ -342,13 +350,19 @@ async def handle_push_response(self, response, **kwargs):
342
350
msg_type = msg_type .decode ()
343
351
344
352
if msg_type == _MOVING_MESSAGE and self .node_moving_push_handler_func :
345
- parser_function = MSG_TYPE_TO_EVENT_PARSER_MAPPING [msg_type ][1 ]
353
+ parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
354
+ msg_type
355
+ ][1 ]
346
356
notification = parser_function (response )
347
357
return await self .node_moving_push_handler_func (notification )
348
358
349
359
if msg_type in _MAINTENANCE_MESSAGES and self .maintenance_push_handler_func :
350
- parser_function = MSG_TYPE_TO_EVENT_PARSER_MAPPING [msg_type ][1 ]
351
- notification_type = MSG_TYPE_TO_EVENT_PARSER_MAPPING [msg_type ][0 ]
360
+ parser_function = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
361
+ msg_type
362
+ ][1 ]
363
+ notification_type = MSG_TYPE_TO_MAINT_NOTIFICATION_PARSER_MAPPING [
364
+ msg_type
365
+ ][0 ]
352
366
notification = parser_function (response , notification_type )
353
367
354
368
if notification is not None :
0 commit comments