From 0103962b8537dd63818bcf8b93fb9f7f75fab3ca Mon Sep 17 00:00:00 2001 From: Mohammad Amin Date: Mon, 23 Sep 2024 16:48:22 +0330 Subject: [PATCH] feat: Added try catch! --- routers/amqp.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/routers/amqp.py b/routers/amqp.py index 19c6433..45fdeb2 100644 --- a/routers/amqp.py +++ b/routers/amqp.py @@ -28,21 +28,24 @@ class Payload(BaseModel): @router.publisher(queue=RabbitQueue(Queue.DISCORD_BOT, durable=True)) async def ask(payload: Payload, logger: Logger): if payload.event == Event.HIVEMIND.INTERACTION_CREATED: - question = payload.content.question - community_id = payload.content.community_id - - logger.info(f"COMMUNITY_ID: {community_id} Received job") - response = query_data_sources(community_id=community_id, query=question) - logger.info(f"COMMUNITY_ID: {community_id} Job finished") - - response_payload = Payload( - event=Event.DISCORD_BOT.INTERACTION_RESPONSE.EDIT, - date=str(datetime.now()), - content={"response": response}, - ) + try: + question = payload.content.question + community_id = payload.content.community_id + + logger.info(f"COMMUNITY_ID: {community_id} Received job") + response = query_data_sources(community_id=community_id, query=question) + logger.info(f"COMMUNITY_ID: {community_id} Job finished") + + response_payload = Payload( + event=Event.DISCORD_BOT.INTERACTION_RESPONSE.EDIT, + date=str(datetime.now()), + content={"response": response}, + ) + return response_payload + except Exception as e: + logger.error(f"Errors While processing job! {e}") else: - raise NotImplementedError( + logger.error( f"No more event available for {Queue.HIVEMIND} queue! " f"Received event: `{payload.event}`" ) - return response_payload