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)