Skip to content

Instantly share code, notes, and snippets.

@jainal09
Created April 10, 2024 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jainal09/f4cff7ef89a9b8813a16398535366d71 to your computer and use it in GitHub Desktop.
Save jainal09/f4cff7ef89a9b8813a16398535366d71 to your computer and use it in GitHub Desktop.
@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