Files
Mqtt_api/Dockerfile
Suriya 57c9e8dbbf Add MQTT webhook bridge with resilient MQTT connection handling
FastAPI service that subscribes to nearle/# on the MQTT broker and forwards
rider status, periodic logs, and profile updates to the Jupiter webhook API.

Includes fixes for a failure mode that took the bridge down silently for
~3.8 days in June 2026, during which it served HTTP 200 on / while
forwarding zero events:

- Retry MQTT connection with backoff instead of letting a single failed
  connect kill the background thread permanently.
- Subscribe inside on_connect so subscriptions are restored after an
  automatic reconnect; the session is clean, so a reconnect previously came
  back subscribed to nothing.
- Add /healthz returning 503 when MQTT is disconnected, so a monitor can
  distinguish a live bridge from a dead one.
- Replace thread-per-message forwarding with a bounded worker pool, which
  keeps memory flat when the upstream API stalls on its 5s timeout.
- Pin requirements.txt to the versions verified in production; it was
  unpinned and had already drifted to paho-mqtt 2.1.0.
- Set PYTHONUNBUFFERED so container logs are not block-buffered.
- Name the compose image nearle-api-image to match the deployed tag.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 19:55:10 +05:30

17 lines
423 B
Docker

FROM python:3.9-slim
WORKDIR /app
# Without this, stdout is block-buffered when not a TTY, so `docker logs` lags far
# behind reality — during the June outage the "MQTT Connection failed" line did not
# surface until long after the failure.
ENV PYTHONUNBUFFERED=1
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY . .
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]