11import logging
2- from typing import Annotated
2+ from typing import Annotated , Any
33
44from fastapi import APIRouter , Depends , FastAPI , status
55from models_library .api_schemas_long_running_tasks .base import TaskProgress
1313 AsyncJobNameData ,
1414)
1515from models_library .products import ProductName
16+ from models_library .rest_error import ErrorGet
1617from models_library .users import UserID
1718from servicelib .fastapi .dependencies import get_app
1819from simcore_service_api_server .models .schemas .tasks import ApiServerEnvelope
@@ -30,7 +31,20 @@ def _get_job_id_data(user_id: UserID, product_name: ProductName) -> AsyncJobName
3031 return AsyncJobNameData (user_id = user_id , product_name = product_name )
3132
3233
33- @router .get ("" , response_model = ApiServerEnvelope [list [TaskGet ]])
34+ _DEFAULT_TASK_STATUS_CODES : dict [int | str , dict [str , Any ]] = {
35+ status .HTTP_500_INTERNAL_SERVER_ERROR : {
36+ "description" : "Internal server error" ,
37+ "model" : ErrorGet ,
38+ },
39+ }
40+
41+
42+ @router .get (
43+ "" ,
44+ response_model = ApiServerEnvelope [list [TaskGet ]],
45+ responses = _DEFAULT_TASK_STATUS_CODES ,
46+ status_code = status .HTTP_200_OK ,
47+ )
3448async def get_async_jobs (
3549 app : Annotated [FastAPI , Depends (get_app )],
3650 user_id : Annotated [UserID , Depends (get_current_user_id )],
@@ -61,7 +75,13 @@ async def get_async_jobs(
6175 return ApiServerEnvelope (data = data )
6276
6377
64- @router .get ("/{task_id}" , response_model = TaskStatus , name = "get_async_job_status" )
78+ @router .get (
79+ "/{task_id}" ,
80+ response_model = TaskStatus ,
81+ name = "get_async_job_status" ,
82+ responses = _DEFAULT_TASK_STATUS_CODES ,
83+ status_code = status .HTTP_200_OK ,
84+ )
6585async def get_async_job_status (
6686 task_id : AsyncJobId ,
6787 user_id : Annotated [UserID , Depends (get_current_user_id )],
@@ -83,7 +103,10 @@ async def get_async_job_status(
83103
84104
85105@router .post (
86- "/{task_id}:cancel" , status_code = status .HTTP_204_NO_CONTENT , name = "cancel_async_job"
106+ "/{task_id}:cancel" ,
107+ status_code = status .HTTP_204_NO_CONTENT ,
108+ name = "cancel_async_job" ,
109+ responses = _DEFAULT_TASK_STATUS_CODES ,
87110)
88111async def cancel_async_job (
89112 task_id : AsyncJobId ,
@@ -97,7 +120,23 @@ async def cancel_async_job(
97120 )
98121
99122
100- @router .get ("/{task_id}/result" , response_model = TaskResult , name = "get_async_job_result" )
123+ @router .get (
124+ "/{task_id}/result" ,
125+ response_model = TaskResult ,
126+ name = "get_async_job_result" ,
127+ responses = {
128+ status .HTTP_404_NOT_FOUND : {
129+ "description" : "Task result not found" ,
130+ "model" : ErrorGet ,
131+ },
132+ status .HTTP_409_CONFLICT : {
133+ "description" : "Task is cancelled" ,
134+ "model" : ErrorGet ,
135+ },
136+ ** _DEFAULT_TASK_STATUS_CODES ,
137+ },
138+ status_code = status .HTTP_200_OK ,
139+ )
101140async def get_async_job_result (
102141 task_id : AsyncJobId ,
103142 user_id : Annotated [UserID , Depends (get_current_user_id )],
0 commit comments