RMQ and DB: Added reconnecting to either if the application goes down
This commit is contained in:
1 parent
482a90ae7b
commit
ac6ca4baf8
3 files changed
+17
-3
No files matched your search
+7
-1
@@ -37,6 +37,11 @@ async def lifespan(app: FastAPI):
|
||||
logger.info("Closing MySQL connection pool...")
|
||||
close_connection_pool()
|
||||
|
||||
def get_rmq_connection(app: FastAPI):
|
||||
connection = getattr(app.state, "rmq_connection", None)
|
||||
if not connection or not connection.is_open:
|
||||
app.state.rmq_connection = create_connection()
|
||||
return app.state.rmq_connection
|
||||
|
||||
api = FastAPI(
|
||||
title="Internal Notifier API",
|
||||
@@ -73,8 +78,9 @@ def receive_notifications(
|
||||
db = Depends(get_db),
|
||||
program_name: str = Depends(verify_api_key_dependency_internal)
|
||||
):
|
||||
rmq_connection = get_rmq_connection(request.app)
|
||||
logger.info(f"Received notifcation data from {program_name} for RMQ")
|
||||
send_message_to_rmq(request.app.state.rmq_connection,notification_data.receipent_user_id,notification_data.message)
|
||||
send_message_to_rmq(rmq_connection,notification_data.receipent_user_id,notification_data.message)
|
||||
logger.info("Successfully delivered message to RMQ")
|
||||
return {"status": "queued"}
|
||||
|
||||
|
||||
Reference in new issue
Block a user