From 62122e0895ef88e634fc12cc7cd6d54430f8c9df Mon Sep 17 00:00:00 2001 From: Aniket Singh Rawat Date: Thu, 2 Nov 2023 21:38:59 +0530 Subject: [PATCH] Added flag to run task in background --- src/teuthology_api/routes/suite.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/teuthology_api/routes/suite.py b/src/teuthology_api/routes/suite.py index 8233ecf..d4e3626 100644 --- a/src/teuthology_api/routes/suite.py +++ b/src/teuthology_api/routes/suite.py @@ -1,6 +1,6 @@ import logging -from fastapi import APIRouter, HTTPException, Depends +from fastapi import APIRouter, HTTPException, Depends, BackgroundTasks from teuthology_api.services.suite import run from teuthology_api.services.helpers import get_token @@ -16,11 +16,17 @@ @router.post("/", status_code=200) -def create_run( +async def create_run( args: SuiteArgs, + background_tasks: BackgroundTasks, access_token: str = Depends(get_token), dry_run: bool = False, logs: bool = False, + background: bool = True, ): + if background: + background_tasks.add_task(run, args, dry_run, logs, access_token) + return {"msg": "Task running in background."} + args = args.model_dump(by_alias=True) return run(args, dry_run, logs, access_token)