From f3c15a198a4138cd72854551556831a27cab7c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Drago=C8=99?= Date: Thu, 3 Oct 2024 11:15:02 +0200 Subject: [PATCH] Create new endpoint for checking service availability via `/status` --- whisper_api.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/whisper_api.py b/whisper_api.py index a3b7af3..a1f3ca6 100644 --- a/whisper_api.py +++ b/whisper_api.py @@ -97,12 +97,23 @@ def get_all_tasks(): return {"data": all_tasks} +@api.get("/status") +def get_status(response: Response): + global current_task + + if current_task and current_task.status == Status.PROCESSING: + response.status_code = status.HTTP_503_SERVICE_UNAVAILABLE + return {"msg": "The worker is currently processing a task. Try again later!"} + + response.status_code = status.HTTP_200_OK + return {"msg": "The worker is available!"} + + @api.post("/tasks", status_code=status.HTTP_201_CREATED) async def create_task( task: Task, background_tasks: BackgroundTasks, response: Response ): global current_task - print(current_task) if current_task and current_task.status == Status.PROCESSING: response.status_code = status.HTTP_503_SERVICE_UNAVAILABLE return {"msg": "The worker is currently processing a task. Try again later!"}