Skip to content

Commit 5222258

Browse files
committed
hide task endpoints from api
1 parent 77d3283 commit 5222258

File tree

7 files changed

+58
-28
lines changed

7 files changed

+58
-28
lines changed

services/api-server/src/simcore_service_api_server/api/routes/tasks.py

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from typing import Annotated, Any
33

4+
from common_library.changelog import create_route_description
45
from fastapi import APIRouter, Depends, FastAPI, status
56
from models_library.api_schemas_long_running_tasks.base import TaskProgress
67
from models_library.api_schemas_long_running_tasks.tasks import (
@@ -15,12 +16,16 @@
1516
from models_library.products import ProductName
1617
from models_library.users import UserID
1718
from servicelib.fastapi.dependencies import get_app
18-
from simcore_service_api_server.models.schemas.tasks import ApiServerEnvelope
1919

20+
from ...models.schemas.base import ApiServerEnvelope
2021
from ...models.schemas.errors import ErrorGet
2122
from ...services_rpc.async_jobs import AsyncJobClient
2223
from ..dependencies.authentication import get_current_user_id, get_product_name
2324
from ..dependencies.tasks import get_async_jobs_client
25+
from ._constants import (
26+
FMSG_CHANGELOG_NEW_IN_VERSION,
27+
create_route_description,
28+
)
2429

2530
router = APIRouter()
2631
_logger = logging.getLogger(__name__)
@@ -43,8 +48,16 @@ def _get_job_id_data(user_id: UserID, product_name: ProductName) -> AsyncJobName
4348
response_model=ApiServerEnvelope[list[TaskGet]],
4449
responses=_DEFAULT_TASK_STATUS_CODES,
4550
status_code=status.HTTP_200_OK,
51+
name="list_tasks",
52+
description=create_route_description(
53+
base="List all tasks",
54+
changelog=[
55+
FMSG_CHANGELOG_NEW_IN_VERSION.format("0.10-rc1"),
56+
],
57+
),
58+
include_in_schema=False, # TO BE RELEASED in 0.10-rc1
4659
)
47-
async def get_async_jobs(
60+
async def list_tasks(
4861
app: Annotated[FastAPI, Depends(get_app)],
4962
user_id: Annotated[UserID, Depends(get_current_user_id)],
5063
product_name: Annotated[ProductName, Depends(get_product_name)],
@@ -60,13 +73,11 @@ async def get_async_jobs(
6073
task_id=f"{job.job_id}",
6174
task_name=job.job_name,
6275
status_href=app_router.url_path_for(
63-
"get_async_job_status", task_id=f"{job.job_id}"
64-
),
65-
abort_href=app_router.url_path_for(
66-
"cancel_async_job", task_id=f"{job.job_id}"
76+
"get_task_status", task_id=f"{job.job_id}"
6777
),
78+
abort_href=app_router.url_path_for("cancel_task", task_id=f"{job.job_id}"),
6879
result_href=app_router.url_path_for(
69-
"get_async_job_result", task_id=f"{job.job_id}"
80+
"get_task_result", task_id=f"{job.job_id}"
7081
),
7182
)
7283
for job in user_async_jobs
@@ -77,11 +88,18 @@ async def get_async_jobs(
7788
@router.get(
7889
"/{task_id}",
7990
response_model=TaskStatus,
80-
name="get_async_job_status",
91+
name="get_task_status",
8192
responses=_DEFAULT_TASK_STATUS_CODES,
8293
status_code=status.HTTP_200_OK,
94+
description=create_route_description(
95+
base="Get task status",
96+
changelog=[
97+
FMSG_CHANGELOG_NEW_IN_VERSION.format("0.10-rc1"),
98+
],
99+
),
100+
include_in_schema=False, # TO BE RELEASED in 0.10-rc1
83101
)
84-
async def get_async_job_status(
102+
async def get_task_status(
85103
task_id: AsyncJobId,
86104
user_id: Annotated[UserID, Depends(get_current_user_id)],
87105
product_name: Annotated[ProductName, Depends(get_product_name)],
@@ -104,10 +122,17 @@ async def get_async_job_status(
104122
@router.post(
105123
"/{task_id}:cancel",
106124
status_code=status.HTTP_204_NO_CONTENT,
107-
name="cancel_async_job",
125+
name="cancel_task",
108126
responses=_DEFAULT_TASK_STATUS_CODES,
127+
description=create_route_description(
128+
base="Cancel task",
129+
changelog=[
130+
FMSG_CHANGELOG_NEW_IN_VERSION.format("0.10-rc1"),
131+
],
132+
),
133+
include_in_schema=False, # TO BE RELEASED in 0.10-rc1
109134
)
110-
async def cancel_async_job(
135+
async def cancel_task(
111136
task_id: AsyncJobId,
112137
user_id: Annotated[UserID, Depends(get_current_user_id)],
113138
product_name: Annotated[ProductName, Depends(get_product_name)],
@@ -122,7 +147,7 @@ async def cancel_async_job(
122147
@router.get(
123148
"/{task_id}/result",
124149
response_model=TaskResult,
125-
name="get_async_job_result",
150+
name="get_task_result",
126151
responses={
127152
status.HTTP_404_NOT_FOUND: {
128153
"description": "Task result not found",
@@ -135,8 +160,15 @@ async def cancel_async_job(
135160
**_DEFAULT_TASK_STATUS_CODES,
136161
},
137162
status_code=status.HTTP_200_OK,
163+
description=create_route_description(
164+
base="Get task result",
165+
changelog=[
166+
FMSG_CHANGELOG_NEW_IN_VERSION.format("0.10-rc1"),
167+
],
168+
),
169+
include_in_schema=False, # TO BE RELEASED in 0.10-rc1
138170
)
139-
async def get_async_job_result(
171+
async def get_task_result(
140172
task_id: AsyncJobId,
141173
user_id: Annotated[UserID, Depends(get_current_user_id)],
142174
product_name: Annotated[ProductName, Depends(get_product_name)],

services/api-server/src/simcore_service_api_server/models/schemas/_base.py renamed to services/api-server/src/simcore_service_api_server/models/schemas/base.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import urllib.parse
2-
from typing import Annotated
2+
from typing import Annotated, Generic, TypeVar
33

44
import packaging.version
55
from models_library.utils.change_case import camel_to_snake
66
from models_library.utils.common_validators import trim_string_before
77
from pydantic import BaseModel, ConfigDict, Field, HttpUrl, StringConstraints
88

9-
from ...models._utils_pydantic import UriSchema
9+
from .._utils_pydantic import UriSchema
1010
from ..basic_types import VersionStr
1111

1212

@@ -83,3 +83,10 @@ def name(self) -> str:
8383
@classmethod
8484
def compose_resource_name(cls, key: str, version: str) -> str:
8585
raise NotImplementedError("Subclasses must implement this method")
86+
87+
88+
DataT = TypeVar("DataT")
89+
90+
91+
class ApiServerEnvelope(BaseModel, Generic[DataT]):
92+
data: DataT

services/api-server/src/simcore_service_api_server/models/schemas/files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .._utils_pydantic import UriSchema
1919
from ..domain.files import File as DomainFile
2020
from ..domain.files import FileName
21-
from ._base import ApiServerInputSchema, ApiServerOutputSchema
21+
from .base import ApiServerInputSchema, ApiServerOutputSchema
2222

2323

2424
class UserFile(ApiServerInputSchema):

services/api-server/src/simcore_service_api_server/models/schemas/jobs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from ..domain.files import File as DomainFile
4040
from ..domain.files import FileInProgramJobData
4141
from ..schemas.files import UserFile
42-
from ._base import ApiServerInputSchema
42+
from .base import ApiServerInputSchema
4343

4444
# JOB SUB-RESOURCES ----------
4545
#

services/api-server/src/simcore_service_api_server/models/schemas/programs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
from ..api_resources import compose_resource_name
1111
from ..basic_types import VersionStr
12-
from ._base import (
12+
from .base import (
1313
ApiServerOutputSchema,
1414
BaseService,
1515
)

services/api-server/src/simcore_service_api_server/models/schemas/solvers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
from models_library.services_types import ServiceKey
1414
from pydantic import BaseModel, ConfigDict, Field, StringConstraints
1515

16-
from ...models.schemas._base import BaseService
1716
from ..api_resources import compose_resource_name
17+
from .base import BaseService
1818

1919
# NOTE:
2020
# - API does NOT impose prefix (simcore)/(services)/comp because does not know anything about registry deployed. This constraint

services/api-server/src/simcore_service_api_server/models/schemas/tasks.py

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)