talentro-commons 0.20.5__py3-none-any.whl → 0.20.7__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.
talentro/services/rabbitmq.py
CHANGED
|
@@ -100,12 +100,12 @@ class RabbitMQ:
|
|
|
100
100
|
f"(TTL: {ttl_ms}ms)")
|
|
101
101
|
|
|
102
102
|
async def consume(
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
103
|
+
self,
|
|
104
|
+
exchange_name: str,
|
|
105
|
+
queue: str,
|
|
106
|
+
callback: Callable,
|
|
107
|
+
dlx_name: Optional[str] = None,
|
|
108
|
+
max_retries: int = 3
|
|
109
109
|
):
|
|
110
110
|
while True:
|
|
111
111
|
try:
|
|
@@ -124,63 +124,45 @@ class RabbitMQ:
|
|
|
124
124
|
await queue_object.bind(exchange, routing_key=queue)
|
|
125
125
|
|
|
126
126
|
async for message in queue_object:
|
|
127
|
+
message_processed = False
|
|
127
128
|
try:
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
129
|
+
event: Event = Event.decode(message.body)
|
|
130
|
+
print(
|
|
131
|
+
f" RabbitMQ ({queue}) - [x] Received event: {event.meta.event_type} (trace: {event.meta.trace_id})")
|
|
132
|
+
await callback(queue, event)
|
|
133
|
+
|
|
134
|
+
# If we reach here, callback succeeded - manually ack
|
|
135
|
+
await message.ack()
|
|
136
|
+
message_processed = True
|
|
137
|
+
|
|
132
138
|
except Exception as e:
|
|
133
139
|
# Handle callback exception - send to retry queue
|
|
134
140
|
print(f" RabbitMQ ({queue}) - ⚠️ Error processing message: {e}")
|
|
135
141
|
traceback.print_exc()
|
|
136
|
-
|
|
142
|
+
|
|
143
|
+
# Get retry count from headers
|
|
144
|
+
x_death = message.headers.get('x-death', [])
|
|
145
|
+
death_count = len(x_death) if x_death else 0
|
|
146
|
+
|
|
147
|
+
print(f" RabbitMQ ({queue}) - Retry attempt {death_count + 1}/{max_retries + 1}")
|
|
148
|
+
|
|
149
|
+
if death_count >= max_retries:
|
|
150
|
+
print(f" RabbitMQ ({queue}) - ❌ Max retries ({max_retries}) exceeded. Sending to DLQ.")
|
|
151
|
+
else:
|
|
152
|
+
print(f" RabbitMQ ({queue}) - Sending to retry queue...")
|
|
153
|
+
|
|
154
|
+
# Nack outside of any context manager
|
|
155
|
+
await message.nack(requeue=False)
|
|
156
|
+
message_processed = True
|
|
137
157
|
|
|
138
158
|
except (aio_pika.exceptions.AMQPConnectionError, aio_pika.exceptions.ChannelClosed):
|
|
139
159
|
print(f" RabbitMQ - Connection lost while consuming {queue}. Retrying in 5 seconds...")
|
|
140
160
|
await asyncio.sleep(5)
|
|
141
161
|
except Exception as e:
|
|
142
162
|
print(f" RabbitMQ - Unexpected error in consumer {queue}: {e}")
|
|
163
|
+
traceback.print_exc()
|
|
143
164
|
await asyncio.sleep(5)
|
|
144
165
|
|
|
145
|
-
@staticmethod
|
|
146
|
-
async def _handle_failed_message(
|
|
147
|
-
message: aio_pika.IncomingMessage,
|
|
148
|
-
queue_name: str,
|
|
149
|
-
exchange_name: str,
|
|
150
|
-
dlx_name: Optional[str] = None,
|
|
151
|
-
max_retries: int = 3
|
|
152
|
-
):
|
|
153
|
-
"""
|
|
154
|
-
Handle failed messages by sending them to the retry queue or DLQ.
|
|
155
|
-
"""
|
|
156
|
-
try:
|
|
157
|
-
# Get death count from headers
|
|
158
|
-
x_death = message.headers.get('x-death', [])
|
|
159
|
-
death_count = 0
|
|
160
|
-
|
|
161
|
-
if x_death:
|
|
162
|
-
# x-death is a list of death info dicts
|
|
163
|
-
death_count = len(x_death)
|
|
164
|
-
|
|
165
|
-
print(f" RabbitMQ ({queue_name}) - Retry attempt {death_count + 1}/{max_retries + 1}")
|
|
166
|
-
|
|
167
|
-
if death_count >= max_retries:
|
|
168
|
-
# Max retries exceeded - send to DLQ
|
|
169
|
-
print(f" RabbitMQ ({queue_name}) - ❌ Max retries ({max_retries}) exceeded. Sending to DLQ.")
|
|
170
|
-
await message.nack(requeue=False)
|
|
171
|
-
else:
|
|
172
|
-
# Still have retries left - send to retry queue
|
|
173
|
-
if dlx_name:
|
|
174
|
-
await message.nack(requeue=False)
|
|
175
|
-
print(f" RabbitMQ ({queue_name}) - Sending to retry queue...")
|
|
176
|
-
else:
|
|
177
|
-
await message.nack(requeue=True)
|
|
178
|
-
print(f" RabbitMQ ({queue_name}) - Message requeued")
|
|
179
|
-
|
|
180
|
-
except Exception as e:
|
|
181
|
-
print(f" RabbitMQ ({queue_name}) - Error handling failed message: {e}")
|
|
182
|
-
await message.nack(requeue=False)
|
|
183
|
-
|
|
184
166
|
async def send_message(self, message: Message):
|
|
185
167
|
# Haal de exchange op
|
|
186
168
|
if message.exchange == "default":
|
|
@@ -29,7 +29,7 @@ talentro/services/caching.py,sha256=mmjhXAMJ_g8D8cJqn15YqZ7ST-G5lD9MS-PmlowI7pU,
|
|
|
29
29
|
talentro/services/clients.py,sha256=vluOrdYdDAQLyGR9-EmogLjA9OUlJtHy0tYD9LhwxKg,2174
|
|
30
30
|
talentro/services/db.py,sha256=cnKCrYG7GwIu7ZZhA25D-yaXaiCJqPpzfcanWquyrBY,822
|
|
31
31
|
talentro/services/google_storage.py,sha256=5r5uiDZD-76Dylc7yyRG5Ni4XNTc9xK8rC0glCRG8_8,6014
|
|
32
|
-
talentro/services/rabbitmq.py,sha256=
|
|
32
|
+
talentro/services/rabbitmq.py,sha256=79WgdUzq2PIx9UUHKxAoi08YaBa7t-NS42eboNVXRVQ,10357
|
|
33
33
|
talentro/util/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
34
34
|
talentro/util/attributes.py,sha256=PgJnn9LMtHkiNIaMov2HQt5944HweD6gRlAHBZrJGPA,448
|
|
35
35
|
talentro/util/enum.py,sha256=YftsoJKnrn8HAjA2Q1tqIYBMrNnlq6m1b34N8hfykbE,155
|
|
@@ -41,6 +41,6 @@ talentro/vacancies/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
|
|
|
41
41
|
talentro/vacancies/dataclasses.py,sha256=E6H5fsZH4IwtBFSLDolzF6u39tEIrANtWiNVoB65P0c,15074
|
|
42
42
|
talentro/vacancies/models.py,sha256=GoXr71CNzU6csf8gdmv84etb3Rm-Cdfigp1yqPI_jjQ,4822
|
|
43
43
|
talentro/vacancies/taxanomy.py,sha256=B6DMq9Wbs0aXFwD9aZveSlLwAC9eq1iCO_KM-FmrV7M,6384
|
|
44
|
-
talentro_commons-0.20.
|
|
45
|
-
talentro_commons-0.20.
|
|
46
|
-
talentro_commons-0.20.
|
|
44
|
+
talentro_commons-0.20.7.dist-info/METADATA,sha256=ocrU8-lGoyvuWhx3CEf1DTXnKN-uqgwi1myOifIyLNw,1507
|
|
45
|
+
talentro_commons-0.20.7.dist-info/WHEEL,sha256=zp0Cn7JsFoX2ATtOhtaFYIiE2rmFAD4OcMhtUki8W3U,88
|
|
46
|
+
talentro_commons-0.20.7.dist-info/RECORD,,
|
|
File without changes
|