Created
April 10, 2024 21:05
-
-
Save jainal09/f4cff7ef89a9b8813a16398535366d71 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@router.post("/create-task/") | |
async def create_task(background_tasks: BackgroundTasks) -> dict: | |
""" | |
Create a task and add it to the queue | |
Args: | |
background_tasks: BackgroundTasks | |
Returns: | |
dict: Response message | |
""" | |
if not read_flag(): | |
raise HTTPException(status_code=503, detail="Service Under Graceful Shutdown") | |
task_id = str(uuid.uuid4()) | |
queue_task(task_id=task_id) | |
print("🚀 Background process started 🚀") | |
background_tasks.add_task(process_task, task_id=task_id, | |
message=f"Task {task_id} processed") | |
background_tasks.add_task(remove_task, task_id=task_id) | |
queue.append(task_id) | |
return {"message": f"Task {task_id} Queued"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment