aboutsummaryrefslogtreecommitdiff
path: root/inventory-service/app/main.py
blob: 81efdd2e0cc3c79afbf25b39eb0c2b5f73f73503 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)