Skip to content

Commit 961a320

Browse files
committed
implement db query to patch registered function jobs
1 parent f545d1c commit 961a320

File tree

3 files changed

+84
-13
lines changed

3 files changed

+84
-13
lines changed

services/web/server/src/simcore_service_webserver/functions/_functions_exceptions.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ class FunctionGroupAccessRightsNotFoundError(WebServerBaseError, RuntimeError):
77
msg_template = user_message(
88
"Group access rights could not be found for Function '{function_id}' in product '{product_name}'."
99
)
10+
11+
12+
class IncompatiblePatchModelError(WebServerBaseError, ValueError):
13+
msg_template = user_message(
14+
"Incompatible patch model for Function '{function_id}' in product '{product_name}'."
15+
)

services/web/server/src/simcore_service_webserver/functions/_functions_repository.py

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,18 +240,9 @@ async def patch_function_job( # noqa: PLR0913
240240
*,
241241
user_id: UserID,
242242
product_name: ProductName,
243-
function_job_uuid: FunctionJobID,
244-
title: str | None,
245-
description: str | None,
246-
**class_specific_data: FunctionJobClassSpecificData | None,
243+
registered_function_job_db: RegisteredFunctionJobDB,
247244
) -> RegisteredFunctionJobDB:
248245

249-
update_params = {
250-
"title": title,
251-
"description": description,
252-
"class_specific_data": class_specific_data,
253-
}
254-
255246
async with transaction_context(get_asyncpg_engine(app), connection) as transaction:
256247
await check_user_api_access_rights(
257248
app,
@@ -264,10 +255,15 @@ async def patch_function_job( # noqa: PLR0913
264255
)
265256
result = await transaction.execute(
266257
function_jobs_table.update()
267-
.where(function_jobs_table.c.uuid == function_job_uuid)
258+
.where(function_jobs_table.c.uuid == registered_function_job_db.uuid)
268259
.values(
260+
inputs=registered_function_job_db.inputs,
261+
outputs=registered_function_job_db.outputs,
262+
function_class=registered_function_job_db.function_class,
263+
class_specific_data=registered_function_job_db.class_specific_data,
264+
title=registered_function_job_db.title,
265+
description=registered_function_job_db.description,
269266
status="created",
270-
**{k: v for k, v in update_params.items() if v is not None},
271267
)
272268
.returning(*_FUNCTION_JOBS_TABLE_COLS)
273269
)

services/web/server/src/simcore_service_webserver/functions/_functions_service.py

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,10 @@
4545
from servicelib.rabbitmq import RPCRouter
4646

4747
from . import _functions_repository
48-
from ._functions_exceptions import FunctionGroupAccessRightsNotFoundError
48+
from ._functions_exceptions import (
49+
FunctionGroupAccessRightsNotFoundError,
50+
IncompatiblePatchModelError,
51+
)
4952

5053
router = RPCRouter()
5154

@@ -110,6 +113,13 @@ async def patch_registered_function_job(
110113
product_name=product_name,
111114
function_job_id=function_job_uuid,
112115
)
116+
if job.function_class != registered_function_job_patch.function_class:
117+
raise IncompatiblePatchModelError(
118+
function_id=job.function_uuid,
119+
product_name=product_name,
120+
)
121+
122+
patched_job = _patch_functionjob(job, registered_function_job_patch)
113123

114124
await _functions_repository.patch_function_job(
115125
app=app,
@@ -781,3 +791,62 @@ def _decode_functionjob(
781791
raise UnsupportedFunctionJobClassError(
782792
function_job_class=functionjob_db.function_class
783793
)
794+
795+
796+
def _patch_functionjob(
797+
function_job_db: RegisteredFunctionJobDB,
798+
patch: RegisteredFunctionJobPatch,
799+
) -> RegisteredFunctionJobDB:
800+
if function_job_db.function_class == FunctionClass.PROJECT:
801+
assert patch.function_class == FunctionClass.PROJECT # nosec
802+
return RegisteredFunctionJobDB(
803+
function_class=FunctionClass.PROJECT,
804+
function_uuid=function_job_db.function_uuid,
805+
title=patch.title or function_job_db.title,
806+
uuid=function_job_db.uuid,
807+
description=patch.description or function_job_db.description,
808+
inputs=function_job_db.inputs,
809+
outputs=function_job_db.outputs,
810+
created=function_job_db.created,
811+
class_specific_data=FunctionClassSpecificData(
812+
project_job_id=patch.project_job_id
813+
or function_job_db.class_specific_data.get("project_job_id"),
814+
job_creation_task_id=patch.job_creation_task_id
815+
or function_job_db.class_specific_data.get("job_creation_task_id"),
816+
),
817+
)
818+
elif function_job_db.function_class == FunctionClass.SOLVER:
819+
assert patch.function_class == FunctionClass.SOLVER # nosec
820+
return RegisteredFunctionJobDB(
821+
function_class=FunctionClass.SOLVER,
822+
function_uuid=function_job_db.function_uuid,
823+
title=patch.title or function_job_db.title,
824+
uuid=function_job_db.uuid,
825+
description=patch.description or function_job_db.description,
826+
inputs=function_job_db.inputs,
827+
outputs=function_job_db.outputs,
828+
created=function_job_db.created,
829+
class_specific_data=FunctionClassSpecificData(
830+
solver_job_id=patch.solver_job_id
831+
or function_job_db.class_specific_data.get("solver_job_id"),
832+
job_creation_task_id=patch.job_creation_task_id
833+
or function_job_db.class_specific_data.get("job_creation_task_id"),
834+
),
835+
)
836+
elif function_job_db.function_class == FunctionClass.PYTHON_CODE:
837+
assert patch.function_class == FunctionClass.PYTHON_CODE # nosec
838+
return RegisteredFunctionJobDB(
839+
function_class=FunctionClass.PYTHON_CODE,
840+
function_uuid=function_job_db.function_uuid,
841+
title=patch.title or function_job_db.title,
842+
uuid=function_job_db.uuid,
843+
description=patch.description or function_job_db.description,
844+
inputs=function_job_db.inputs,
845+
outputs=function_job_db.outputs,
846+
created=function_job_db.created,
847+
class_specific_data=function_job_db.class_specific_data,
848+
)
849+
else:
850+
raise UnsupportedFunctionJobClassError(
851+
function_job_class=function_job_db.function_class
852+
)

0 commit comments

Comments
 (0)