diff options
Diffstat (limited to 'inventory-service/app/main.py')
| -rw-r--r-- | inventory-service/app/main.py | 33 |
1 files changed, 33 insertions, 0 deletions
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") + + [email protected]_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() + + [email protected]("/health") +def health_check(): + return {"status": "working"} + + +if __name__ == "__main__": + uvicorn.run("app.main:app", host="127.0.0.1", port=8001, reload=True) |
