From a478fd5c4bfd76490c8f95781ae1b6d8175287c6 Mon Sep 17 00:00:00 2001 From: "Felix T.J. Dietrich" Date: Thu, 1 Aug 2024 23:50:05 +0200 Subject: [PATCH] add health check --- server/webhook-distributor/README.md | 2 +- server/webhook-distributor/main.py | 20 ++++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/server/webhook-distributor/README.md b/server/webhook-distributor/README.md index 79845d58..7bb5eee0 100644 --- a/server/webhook-distributor/README.md +++ b/server/webhook-distributor/README.md @@ -16,4 +16,4 @@ To register a destination, send a POST request to `/register` with the following ### Send a webhook -To send a webhook, send a POST request to `/webhook`. The webhook will be forwarded to all registered destinations. \ No newline at end of file +To send a webhook, send a POST request to `/`. The webhook will be forwarded to all registered destinations. \ No newline at end of file diff --git a/server/webhook-distributor/main.py b/server/webhook-distributor/main.py index dcf54646..41192bff 100644 --- a/server/webhook-distributor/main.py +++ b/server/webhook-distributor/main.py @@ -1,5 +1,5 @@ from typing import Set -from fastapi import FastAPI, Request +from fastapi import FastAPI, Request, status from pydantic import BaseModel import httpx @@ -21,7 +21,7 @@ def register_destination(destination: Destination): return { "message": "Destination registered successfully" } -@app.post("/webhook") +@app.post("/") async def send_webhook(request: Request): payload = await request.json() failed_destinations = [] @@ -41,3 +41,19 @@ async def send_webhook(request: Request): "failed": len(failed_destinations), "success_destinations": len(destinations), } + + +class HealthCheck(BaseModel): + status: str = "OK" + + +@app.get( + "/health", + tags=["healthcheck"], + summary="Perform a Health Check", + response_description="Return HTTP Status Code 200 (OK)", + status_code=status.HTTP_200_OK, + response_model=HealthCheck, +) +def get_health() -> HealthCheck: + return HealthCheck(status="OK") \ No newline at end of file