Skip to content

Commit 41adf50

Browse files
committed
refactor: rename ComputationsApi to DirectorV2RestClient and update method names for clarity
1 parent d29840c commit 41adf50

File tree

3 files changed

+22
-16
lines changed

3 files changed

+22
-16
lines changed

services/web/server/src/simcore_service_webserver/director_v2/_client.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ async def is_healthy(app: web.Application) -> bool:
4242
return False
4343

4444

45-
class ComputationsApi:
45+
class DirectorV2RestClient:
4646
def __init__(self, app: web.Application) -> None:
4747
self._app = app
4848
self._settings: DirectorV2Settings = get_plugin_settings(app)
4949

50-
async def get(
50+
async def get_computation(
5151
self, project_id: ProjectID, user_id: UserID
5252
) -> DirectorV2ComputationGet:
5353
computation_task_out = await request_director_v2(
@@ -61,7 +61,7 @@ async def get(
6161
assert isinstance(computation_task_out, dict) # nosec
6262
return DirectorV2ComputationGet.model_validate(computation_task_out)
6363

64-
async def start(
64+
async def start_computation(
6565
self, project_id: ProjectID, user_id: UserID, product_name: str, **options
6666
) -> str:
6767
computation_task_out = await request_director_v2(
@@ -80,7 +80,7 @@ async def start(
8080
computation_task_out_id: str = computation_task_out["id"]
8181
return computation_task_out_id
8282

83-
async def stop(self, project_id: ProjectID, user_id: UserID):
83+
async def stop_computation(self, project_id: ProjectID, user_id: UserID):
8484
await request_director_v2(
8585
self._app,
8686
"POST",
@@ -90,13 +90,13 @@ async def stop(self, project_id: ProjectID, user_id: UserID):
9090
)
9191

9292

93-
_APP_KEY = f"{__name__}.{ComputationsApi.__name__}"
93+
_APP_KEY = f"{__name__}.{DirectorV2RestClient.__name__}"
9494

9595

96-
def get_client(app: web.Application) -> ComputationsApi | None:
97-
app_key: ComputationsApi | None = app.get(_APP_KEY)
96+
def get_client(app: web.Application) -> DirectorV2RestClient | None:
97+
app_key: DirectorV2RestClient | None = app.get(_APP_KEY)
9898
return app_key
9999

100100

101-
def set_client(app: web.Application, obj: ComputationsApi):
101+
def set_client(app: web.Application, obj: DirectorV2RestClient):
102102
app[_APP_KEY] = obj

services/web/server/src/simcore_service_webserver/director_v2/_controller/rest.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
from ...products import products_web
2828
from ...security.decorators import permission_required
2929
from ...utils_aiohttp import envelope_json_response
30-
from .. import _client, _service
30+
from .. import _service
31+
from .._client import DirectorV2RestClient
3132
from .._service_abc import CommitID, get_project_run_policy
3233
from ._rest_exceptions import handle_rest_requests_exceptions
3334

@@ -106,10 +107,12 @@ async def start_computation(request: web.Request) -> web.Response:
106107
else True
107108
)
108109

109-
computations = _client.ComputationsApi(request.app)
110+
computations = DirectorV2RestClient(request.app)
110111
_started_pipelines_ids = await asyncio.gather(
111112
*[
112-
computations.start(pid, req_ctx.user_id, req_ctx.product_name, **options)
113+
computations.start_computation(
114+
pid, req_ctx.user_id, req_ctx.product_name, **options
115+
)
113116
for pid in running_project_ids
114117
]
115118
)
@@ -134,7 +137,7 @@ async def start_computation(request: web.Request) -> web.Response:
134137
@handle_rest_requests_exceptions
135138
async def stop_computation(request: web.Request) -> web.Response:
136139
req_ctx = RequestContext.model_validate(request)
137-
computations = _client.ComputationsApi(request.app)
140+
computations = DirectorV2RestClient(request.app)
138141
run_policy = get_project_run_policy(request.app)
139142
assert run_policy # nosec
140143

@@ -148,7 +151,7 @@ async def stop_computation(request: web.Request) -> web.Response:
148151
)
149152

150153
await asyncio.gather(
151-
*[computations.stop(pid, req_ctx.user_id) for pid in project_ids]
154+
*[computations.stop_computation(pid, req_ctx.user_id) for pid in project_ids]
152155
)
153156
return web.json_response(status=status.HTTP_204_NO_CONTENT)
154157

@@ -159,7 +162,7 @@ async def stop_computation(request: web.Request) -> web.Response:
159162
@permission_required("project.read")
160163
@handle_rest_requests_exceptions
161164
async def get_computation(request: web.Request) -> web.Response:
162-
computations = _client.ComputationsApi(request.app)
165+
computations = DirectorV2RestClient(request.app)
163166
run_policy = get_project_run_policy(request.app)
164167
assert run_policy # nosec
165168

@@ -175,7 +178,10 @@ async def get_computation(request: web.Request) -> web.Response:
175178
)
176179

177180
list_computation_tasks = await asyncio.gather(
178-
*[computations.get(project_id=pid, user_id=user_id) for pid in project_ids]
181+
*[
182+
computations.get_computation(project_id=pid, user_id=user_id)
183+
for pid in project_ids
184+
]
179185
)
180186

181187
assert len(list_computation_tasks) == len(project_ids) # nosec

services/web/server/src/simcore_service_webserver/director_v2/plugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def setup_director_v2(app: web.Application):
2727
assert app[APP_SETTINGS_KEY].WEBSERVER_DIRECTOR_V2 # nosec
2828

2929
# client to communicate with director-v2 service
30-
_client.set_client(app, _client.ComputationsApi(app))
30+
_client.set_client(app, _client.DirectorV2RestClient(app))
3131

3232
# routes at the web-server app
3333
setup_rest(app)

0 commit comments

Comments
 (0)