nebu 0.1.20__py3-none-any.whl → 0.1.22__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nebu/processors/consumer.py +34 -17
- {nebu-0.1.20.dist-info → nebu-0.1.22.dist-info}/METADATA +1 -1
- {nebu-0.1.20.dist-info → nebu-0.1.22.dist-info}/RECORD +6 -6
- {nebu-0.1.20.dist-info → nebu-0.1.22.dist-info}/WHEEL +0 -0
- {nebu-0.1.20.dist-info → nebu-0.1.22.dist-info}/licenses/LICENSE +0 -0
- {nebu-0.1.20.dist-info → nebu-0.1.22.dist-info}/top_level.txt +0 -0
nebu/processors/consumer.py
CHANGED
@@ -6,7 +6,7 @@ import sys
|
|
6
6
|
import time
|
7
7
|
import traceback
|
8
8
|
from datetime import datetime
|
9
|
-
from typing import
|
9
|
+
from typing import Dict, TypeVar
|
10
10
|
|
11
11
|
import redis
|
12
12
|
import socks
|
@@ -246,6 +246,9 @@ except Exception as e:
|
|
246
246
|
|
247
247
|
# Create consumer group if it doesn't exist
|
248
248
|
try:
|
249
|
+
# Assert types before use
|
250
|
+
assert isinstance(REDIS_STREAM, str)
|
251
|
+
assert isinstance(REDIS_CONSUMER_GROUP, str)
|
249
252
|
r.xgroup_create(REDIS_STREAM, REDIS_CONSUMER_GROUP, id="0", mkstream=True)
|
250
253
|
print(f"Created consumer group {REDIS_CONSUMER_GROUP} for stream {REDIS_STREAM}")
|
251
254
|
except ResponseError as e:
|
@@ -257,19 +260,34 @@ except ResponseError as e:
|
|
257
260
|
|
258
261
|
|
259
262
|
# Function to process messages
|
260
|
-
def process_message(message_id:
|
263
|
+
def process_message(message_id: str, message_data: Dict[str, str]) -> None:
|
261
264
|
# Initialize variables that need to be accessible in the except block
|
262
265
|
return_stream = None
|
263
266
|
user_id = None
|
264
267
|
|
268
|
+
print(f"Message data inner: {message_data}")
|
269
|
+
|
265
270
|
try:
|
266
|
-
#
|
267
|
-
|
268
|
-
|
271
|
+
# Extract the JSON string payload from the 'data' field
|
272
|
+
payload_str = message_data.get("data")
|
273
|
+
|
274
|
+
# decode_responses=True should mean payload_str is a string if found.
|
275
|
+
if not payload_str:
|
276
|
+
raise ValueError(
|
277
|
+
f"Missing or invalid 'data' field (expected string): {message_data}"
|
278
|
+
)
|
269
279
|
|
270
|
-
#
|
271
|
-
|
272
|
-
|
280
|
+
# Parse the JSON string into a dictionary
|
281
|
+
try:
|
282
|
+
raw_payload = json.loads(payload_str)
|
283
|
+
except json.JSONDecodeError as json_err:
|
284
|
+
raise ValueError(f"Failed to parse JSON payload: {json_err}") from json_err
|
285
|
+
|
286
|
+
# Validate that raw_payload is a dictionary as expected
|
287
|
+
if not isinstance(raw_payload, dict):
|
288
|
+
raise TypeError(
|
289
|
+
f"Expected parsed payload to be a dictionary, but got {type(raw_payload)}"
|
290
|
+
)
|
273
291
|
|
274
292
|
print(f"Raw payload: {raw_payload}")
|
275
293
|
|
@@ -287,10 +305,10 @@ def process_message(message_id: bytes, message_data: Dict[bytes, bytes]) -> None
|
|
287
305
|
|
288
306
|
# --- Health Check Logic based on kind ---
|
289
307
|
if kind == "HealthCheck":
|
290
|
-
print(f"Received HealthCheck message {message_id
|
308
|
+
print(f"Received HealthCheck message {message_id}")
|
291
309
|
health_response = {
|
292
310
|
"kind": "StreamResponseMessage", # Respond with a standard message kind
|
293
|
-
"id": message_id
|
311
|
+
"id": message_id,
|
294
312
|
"content": {"status": "healthy", "checked_message_id": msg_id},
|
295
313
|
"status": "success",
|
296
314
|
"created_at": datetime.now().isoformat(),
|
@@ -306,7 +324,7 @@ def process_message(message_id: bytes, message_data: Dict[bytes, bytes]) -> None
|
|
306
324
|
assert isinstance(REDIS_STREAM, str)
|
307
325
|
assert isinstance(REDIS_CONSUMER_GROUP, str)
|
308
326
|
r.xack(REDIS_STREAM, REDIS_CONSUMER_GROUP, message_id)
|
309
|
-
print(f"Acknowledged HealthCheck message {message_id
|
327
|
+
print(f"Acknowledged HealthCheck message {message_id}")
|
310
328
|
return # Exit early for health checks
|
311
329
|
# --- End Health Check Logic ---
|
312
330
|
|
@@ -392,7 +410,7 @@ def process_message(message_id: bytes, message_data: Dict[bytes, bytes]) -> None
|
|
392
410
|
# Prepare the response
|
393
411
|
response = {
|
394
412
|
"kind": "StreamResponseMessage",
|
395
|
-
"id": message_id
|
413
|
+
"id": message_id,
|
396
414
|
"content": result,
|
397
415
|
"status": "success",
|
398
416
|
"created_at": datetime.now().isoformat(),
|
@@ -406,9 +424,7 @@ def process_message(message_id: bytes, message_data: Dict[bytes, bytes]) -> None
|
|
406
424
|
# Assert type again closer to usage for type checker clarity
|
407
425
|
assert isinstance(return_stream, str)
|
408
426
|
r.xadd(return_stream, {"data": json.dumps(response)})
|
409
|
-
print(
|
410
|
-
f"Processed message {message_id.decode('utf-8')}, result sent to {return_stream}"
|
411
|
-
)
|
427
|
+
print(f"Processed message {message_id}, result sent to {return_stream}")
|
412
428
|
|
413
429
|
# Acknowledge the message
|
414
430
|
# Assert types again closer to usage for type checker clarity
|
@@ -417,13 +433,13 @@ def process_message(message_id: bytes, message_data: Dict[bytes, bytes]) -> None
|
|
417
433
|
r.xack(REDIS_STREAM, REDIS_CONSUMER_GROUP, message_id)
|
418
434
|
|
419
435
|
except Exception as e:
|
420
|
-
print(f"Error processing message {message_id
|
436
|
+
print(f"Error processing message {message_id}: {e}")
|
421
437
|
traceback.print_exc()
|
422
438
|
|
423
439
|
# Prepare the error response
|
424
440
|
error_response = {
|
425
441
|
"kind": "StreamResponseMessage",
|
426
|
-
"id": message_id
|
442
|
+
"id": message_id,
|
427
443
|
"content": {
|
428
444
|
"error": str(e),
|
429
445
|
"traceback": traceback.format_exc(),
|
@@ -462,6 +478,7 @@ while True:
|
|
462
478
|
|
463
479
|
# Read from stream with blocking
|
464
480
|
streams = {REDIS_STREAM: ">"} # '>' means read only new messages
|
481
|
+
# The type checker still struggles here, but the runtime types are asserted.
|
465
482
|
messages = r.xreadgroup( # type: ignore[arg-type]
|
466
483
|
REDIS_CONSUMER_GROUP, consumer_name, streams, count=1, block=5000
|
467
484
|
)
|
@@ -6,15 +6,15 @@ nebu/containers/container.py,sha256=yb7KaPTVXnEEAlrpdlUi4HNqF6P7z9bmwAILGlq6iqU,
|
|
6
6
|
nebu/containers/decorator.py,sha256=uFtzlAXRHYZECJ-NPusY7oN9GXvdHrHDd_JNrIGr8aQ,3244
|
7
7
|
nebu/containers/models.py,sha256=0j6NGy4yto-enRDh_4JH_ZTbHrLdSpuMOqNQPnIrwC4,6815
|
8
8
|
nebu/containers/server.py,sha256=yFa2Y9PzBn59E1HftKiv0iapPonli2rbGAiU6r-wwe0,2513
|
9
|
-
nebu/processors/consumer.py,sha256=
|
9
|
+
nebu/processors/consumer.py,sha256=qQQWNAZnY7A7Af6SNMYVXN3NOG_9dNK5iE_0us-o2Po,19659
|
10
10
|
nebu/processors/decorate.py,sha256=AeG1c1n8JtcexxAEf2sF2L2eKwVDaNQ5gvPs6EpazKo,34789
|
11
11
|
nebu/processors/default.py,sha256=W4slJenG59rvyTlJ7gRp58eFfXcNOTT2Hfi6zzJAobI,365
|
12
12
|
nebu/processors/models.py,sha256=GvnI8UJrQSjHo2snP07cPfisCH90cEGTY-PZV5_AtXI,3654
|
13
13
|
nebu/processors/processor.py,sha256=oy2YdI-cy6qQWxrZhpZahJV46oWZlu_Im-jm811R_oo,9667
|
14
14
|
nebu/redis/models.py,sha256=coPovAcVXnOU1Xh_fpJL4PO3QctgK9nBe5QYoqEcnxg,1230
|
15
15
|
nebu/services/service.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
16
|
-
nebu-0.1.
|
17
|
-
nebu-0.1.
|
18
|
-
nebu-0.1.
|
19
|
-
nebu-0.1.
|
20
|
-
nebu-0.1.
|
16
|
+
nebu-0.1.22.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
17
|
+
nebu-0.1.22.dist-info/METADATA,sha256=5knaeQTz1sBQEH2za1s6-499HYkNfNxLZgxvpRUEO6Y,1678
|
18
|
+
nebu-0.1.22.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
19
|
+
nebu-0.1.22.dist-info/top_level.txt,sha256=uLIbEKJeGSHWOAJN5S0i5XBGwybALlF9bYoB1UhdEgQ,5
|
20
|
+
nebu-0.1.22.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|