From 8e796c9cfcd65f6225a6ae3ec2a4419f265b0ebc Mon Sep 17 00:00:00 2001 From: alex Date: Fri, 17 Jul 2026 18:16:35 +0200 Subject: inventory-service init --- inventory-service/app/main.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 inventory-service/app/main.py (limited to 'inventory-service/app/main.py') diff --git a/inventory-service/app/main.py b/inventory-service/app/main.py new file mode 100644 index 0000000..81efdd2 --- /dev/null +++ b/inventory-service/app/main.py @@ -0,0 +1,33 @@ +import threading +import uvicorn +from fastapi import FastAPI +from app.api.v1.api import api_router +from app.core.config import settings +from app.kafka_consumer import start_consumer_loop + +app = FastAPI(title=settings.PROJECT_NAME) + +app.include_router(api_router, prefix="/api/v1") + + +@app.on_event("startup") +def startup_event(): + """ + On startup, launch the Kafka consumer in a daemon background thread + so the event loop and the HTTP server run concurrently. + """ + consumer_thread = threading.Thread( + target=start_consumer_loop, + daemon=True, + name="kafka-consumer", + ) + consumer_thread.start() + + +@app.get("/health") +def health_check(): + return {"status": "working"} + + +if __name__ == "__main__": + uvicorn.run("app.main:app", host="127.0.0.1", port=8001, reload=True) -- cgit v1.2.3