Skip to content

Commit

Permalink
Create new endpoint for checking service availability
Browse files Browse the repository at this point in the history
via `/status`
  • Loading branch information
greenw0lf committed Oct 3, 2024
1 parent 5f13238 commit f3c15a1
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion whisper_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!"}
Expand Down

0 comments on commit f3c15a1

Please sign in to comment.