Add RabbitMQ healthcheck

This commit is contained in:
Songbird
2025-11-14 12:29:00 +01:00
parent a05a8235ea
commit 486b6db01a
3 changed files with 33 additions and 1 deletions

View File

@@ -599,6 +599,12 @@ services:
LOG_LEVEL: INFO
networks:
- fuzzforge-network
healthcheck:
test: ["CMD", "python", "healthcheck.py"]
interval: 30s
timeout: 5s
retries: 3
start_period: 10s
restart: unless-stopped
# ============================================================================

View File

@@ -6,6 +6,6 @@ WORKDIR /app
COPY requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
COPY app.py ./
COPY app.py healthcheck.py ./
CMD ["python", "app.py"]

View File

@@ -0,0 +1,26 @@
"""Simple healthcheck to verify RabbitMQ connectivity."""
from __future__ import annotations
import os
import sys
import pika
def main() -> int:
rabbit_url = os.getenv("RABBITMQ_URL", "amqp://ingest:ingest@rabbitmq:5672/")
try:
connection = pika.BlockingConnection(pika.URLParameters(rabbit_url))
try:
channel = connection.channel()
channel.basic_qos(prefetch_count=1)
finally:
connection.close()
except Exception as exc: # pragma: no cover - run-time diagnostic
print(f"[healthcheck] RabbitMQ unavailable: {exc}", file=sys.stderr)
return 1
return 0
if __name__ == "__main__":
raise SystemExit(main())