Skip to content

Commit

Permalink
feat: Handle exceptions to sentry and dlx in TemplateTypeConsumer
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro-Meireles committed Sep 21, 2023
1 parent ed3fa0b commit 910c0a8
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions marketplace/projects/consumers/template_type_consumer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import amqp
from sentry_sdk import capture_exception

from marketplace.event_driven.parsers import JSONParser
from marketplace.event_driven.consumers import EDAConsumer
Expand All @@ -7,10 +8,16 @@

class TemplateTypeConsumer(EDAConsumer): # pragma: no cover
def consume(self, message: amqp.Message):
body = JSONParser.parse(message.body)
print(f"[TemplateTypeConsumer] - Consuming a message. Body: {message.body}")

print(f"[TemplateTypeConsumer] - Consuming a message. Body: {body}")
try:
body = JSONParser.parse(message.body)

create_template_type(uuid=body.get("uuid"), project_uuid=body.get("project_uuid"), name=body.get("name"))
create_template_type(uuid=body.get("uuid"), project_uuid=body.get("project_uuid"), name=body.get("name"))

message.channel.basic_ack(message.delivery_tag)
message.channel.basic_ack(message.delivery_tag)

except Exception as exception:
capture_exception(exception)
message.channel.basic_reject(message.delivery_tag, requeue=False)
print(f"[ProjectConsumer] - Message rejected by: {exception}")

0 comments on commit 910c0a8

Please sign in to comment.