-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
76 lines (54 loc) · 1.99 KB
/
main.py
File metadata and controls
76 lines (54 loc) · 1.99 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import asyncio
from fastapi import FastAPI
from src.common.event_bus import EventBus
from src.common.utils import get_logger
from src.common.models import DriverLocationEvent
from src.driver-location-service.location_store import DriverLocationStore
from src.driver-location-service.consumer import DriverLocationConsumer
from src.driver-location-service.api_router import router, DRIVER_STORE
# ------------------------------------------------------------
# INITIALIZATION
# ------------------------------------------------------------
logger = get_logger("DriverLocationMain")
event_bus = EventBus()
driver_store = DriverLocationStore()
app = FastAPI(
title="Driver Location Service",
description="Real-time driver location ingestion service for the ride-sharing platform.",
version="1.0.0",
)
# ------------------------------------------------------------
# STARTUP SEQUENCE
# ------------------------------------------------------------
@app.on_event("startup")
async def startup_event():
logger.info("Starting Driver Location Service...")
# Inject store into API router
global DRIVER_STORE
DRIVER_STORE = driver_store
# Initialize consumer
consumer = DriverLocationConsumer(
event_bus=event_bus,
store=driver_store
)
# Subscribe to driver location update events
await event_bus.subscribe(
"driver_location_updates",
consumer.handle_driver_location
)
logger.info("Driver Location Service started successfully.")
# ------------------------------------------------------------
# ROUTER
# ------------------------------------------------------------
app.include_router(router, prefix="/driver-location")
# ------------------------------------------------------------
# LOCAL RUNNER
# ------------------------------------------------------------
if __name__ == "__main__":
import uvicorn
uvicorn.run(
"src.driver-location-service.main:app",
host="0.0.0.0",
port=8003,
reload=True
)