Service Status
GET /
Returns the current service status and polling configuration.This endpoint accepts no parameters.
- Returns static configuration values from
core/settings.py poll_interval_secondsis controlled byTERMINAL_POLLING_INTERVAL_SECONDSenvironment variable (default: 60)- All polling flags are controlled by
LOCATION_POLL_ENABLEDenvironment variable
Health Check
GET /health
Simple health check endpoint for load balancers and monitoring. Response:- Returns immediately without database or external service checks
- Used by Docker healthcheck and Kubernetes liveness probes
Vehicle Locations
GET /locations/current
Get current vehicle (tractor) locations from the database. This is a DB-first read endpoint that returns data with staleness metadata.Maximum number of vehicles to return (1-1000)
ISO 8601 timestamp - only return vehicles updated after this time (e.g.,
2025-11-11T16:00:00Z)| Header | Description |
|---|---|
X-Data-Source | Always db |
X-Stale-Ms | Milliseconds since most recent update |
ETag | MD5 hash of payload for caching |
Last-Modified | HTTP date of most recent update |
Retry-After | Seconds to wait (only on 202 status) |
- Database Query: Reads directly from the
tractorstable usingget_latest_vehicle_locations()function - Window Function: Uses PostgreSQL
ROW_NUMBER()window function to get the latest row pervehicle_id, ordered byupdated_at DESC - Filters Applied:
- Only vehicles with non-null
vehicle_id,latitude, andlongitude - Optional
sincetimestamp filter
- Only vehicles with non-null
- Cold-Start Handling: If no data in DB and a poll is in progress, waits up to
COLD_START_WAIT_MS(default: 250ms) before returning 202 - Staleness Calculation: Compares current time to
max(updated_at)to calculatestaleMs - Stale Threshold: Data is considered stale if
staleMs > VEHICLE_MAX_STALE_SECONDS * 1000(default: 45 seconds)
- The
tractorstable is populated by theLocationPollingServicebackground service - Polling interval: 60 seconds when SSE clients connected, 300 seconds when idle
- Data originates from Terminal API (
/tsp/v1/vehicles/locations) which aggregates ELD providers (Motive, Samsara, Geotab)
Real-Time Location Stream
GET /stream/locations
Server-Sent Events (SSE) endpoint for real-time vehicle location updates. Event Types:connected
connected
Sent immediately when client connects.
location_update
location_update
Sent when new location data is available (every 60 seconds during active polling).
heartbeat
heartbeat
Sent every 30 seconds to keep connection alive.
- Connection: Client connects via
EventSourceAPI - Client Registration:
SSEConnectionManagercreates a unique client ID and asyncio queue for this client - Polling Wake-up: Notifies
LocationPollingServiceto switch from slow polling (300s) to fast polling (60s) - Initial Data: Immediately reads from
tractorstable viaget_latest_vehicle_locations()and sends as firstlocation_updateevent - Live Updates:
LocationPollingServicebroadcasts to all connected clients after each poll cycle - Data Enrichment: Before broadcasting, locations are enriched with:
- Driver names (via
DriverNameMapperfrom Terminal API driver data) - Tractor numbers (via
TractorNumberMapper)
- Driver names (via
- Heartbeat: Sends
:heartbeatcomment everySSE_HEARTBEAT_INTERVAL_SECONDS(default: 30s) to prevent connection timeout - Disconnect Detection: Checks
request.is_disconnected()every 1.5 seconds - Cleanup: On disconnect, removes client from
SSEConnectionManager
| Header | Value |
|---|---|
Content-Type | text/event-stream |
Cache-Control | no-cache |
Connection | keep-alive |
X-Accel-Buffering | no (disables nginx buffering) |

