11from  dataclasses  import  dataclass 
2- from  typing  import  Annotated 
32
43import  jsonschema 
54from  common_library .exclude  import  as_dict_exclude_none 
65from  models_library .functions  import  (
6+     BatchUpdateRegisteredFunctionJobs ,
77    FunctionClass ,
88    FunctionID ,
99    FunctionInputs ,
1010    FunctionJobCollectionID ,
1111    FunctionJobID ,
1212    FunctionJobList ,
13+     FunctionJobPatchRequest ,
14+     FunctionJobPatchRequestList ,
1315    FunctionSchemaClass ,
1416    ProjectFunctionJob ,
1517    RegisteredFunction ,
1618    RegisteredFunctionJob ,
1719    RegisteredProjectFunctionJobPatch ,
18-     RegisteredProjectFunctionJobPatchInput ,
19-     RegisteredProjectFunctionJobPatchInputList ,
2020    RegisteredSolverFunctionJobPatch ,
21-     RegisteredSolverFunctionJobPatchInput ,
22-     RegisteredSolverFunctionJobPatchInputList ,
2321    SolverFunctionJob ,
2422)
2523from  models_library .functions_errors  import  (
3129from  models_library .rest_pagination  import  PageMetaInfoLimitOffset , PageOffsetInt 
3230from  models_library .rpc_pagination  import  PageLimitInt 
3331from  models_library .users  import  UserID 
34- from  pydantic  import  Field ,  TypeAdapter , ValidationError ,  validate_call 
32+ from  pydantic  import  TypeAdapter , ValidationError 
3533from  simcore_service_api_server ._service_functions  import  FunctionService 
3634from  simcore_service_api_server .services_rpc .storage  import  StorageService 
3735
@@ -210,62 +208,51 @@ async def pre_register_function_jobs(
210208            for  job , input_  in  zip (jobs , job_inputs )
211209        ]
212210
213-     @validate_call  
214-     async  def  patch_registered_function_job (
211+     async  def  batch_patch_registered_function_job (
215212        self ,
216213        * ,
217214        user_id : UserID ,
218215        product_name : ProductName ,
219-         patches : Annotated [
220-             list [FunctionJobPatch ],
221-             Field (max_length = 50 , min_length = 1 ),
222-         ],
223-     ) ->  list [RegisteredFunctionJob ]:
224-         patch_inputs : list [
225-             RegisteredProjectFunctionJobPatchInput 
226-             |  RegisteredSolverFunctionJobPatchInput 
227-         ] =  []
228-         for  patch  in  patches :
216+         function_job_patches : list [FunctionJobPatch ],
217+     ) ->  BatchUpdateRegisteredFunctionJobs :
218+         patch_inputs : FunctionJobPatchRequestList  =  []
219+         for  patch  in  function_job_patches :
229220            if  patch .function_class  ==  FunctionClass .PROJECT :
230221                patch_inputs .append (
231-                     RegisteredProjectFunctionJobPatchInput (
222+                     FunctionJobPatchRequest (
232223                        uid = patch .function_job_id ,
233224                        patch = RegisteredProjectFunctionJobPatch (
234225                            title = None ,
235226                            description = None ,
236227                            inputs = None ,
237228                            outputs = None ,
238229                            job_creation_task_id = patch .job_creation_task_id ,
239-                             project_job_id = patch . project_job_id ,
230+                             project_job_id = None ,
240231                        ),
241232                    )
242233                )
243234            elif  patch .function_class  ==  FunctionClass .SOLVER :
244235                patch_inputs .append (
245-                     RegisteredSolverFunctionJobPatchInput (
236+                     FunctionJobPatchRequest (
246237                        uid = patch .function_job_id ,
247238                        patch = RegisteredSolverFunctionJobPatch (
248239                            title = None ,
249240                            description = None ,
250241                            inputs = None ,
251242                            outputs = None ,
252243                            job_creation_task_id = patch .job_creation_task_id ,
253-                             solver_job_id = patch . solver_job_id ,
244+                             solver_job_id = None ,
254245                        ),
255246                    )
256247                )
257248            else :
258249                raise  UnsupportedFunctionClassError (
259250                    function_class = patch .function_class ,
260251                )
261- 
262-         return  await  self ._web_rpc_client .patch_registered_function_job (
252+         return  await  self ._web_rpc_client .batch_patch_registered_function_job (
263253            user_id = user_id ,
264254            product_name = product_name ,
265-             registered_function_job_patch_inputs = TypeAdapter (
266-                 RegisteredProjectFunctionJobPatchInputList 
267-                 |  RegisteredSolverFunctionJobPatchInputList 
268-             ).validate_python (patch_inputs ),
255+             function_job_patch_requests = patch_inputs ,
269256        )
270257
271258    async  def  run_function (
@@ -294,20 +281,22 @@ async def run_function(
294281                job_id = study_job .id ,
295282                pricing_spec = pricing_spec ,
296283            )
297-             registered_jobs  =  await  self .patch_registered_function_job (
284+             registered_job  =  await  self . _web_rpc_client .patch_registered_function_job (
298285                user_id = self .user_id ,
299286                product_name = self .product_name ,
300-                 patches = [
301-                     FunctionJobPatch (
302-                         function_class = FunctionClass .PROJECT ,
303-                         function_job_id = pre_registered_function_job_data .function_job_id ,
287+                 function_job_patch_request = FunctionJobPatchRequest (
288+                     uid = pre_registered_function_job_data .function_job_id ,
289+                     patch = RegisteredProjectFunctionJobPatch (
290+                         title = None ,
291+                         description = None ,
292+                         inputs = None ,
293+                         outputs = None ,
304294                        job_creation_task_id = None ,
305295                        project_job_id = study_job .id ,
306-                     )
307-                 ] ,
296+                     ), 
297+                 ) ,
308298            )
309-             assert  len (registered_jobs ) ==  1 
310-             return  registered_jobs [0 ]
299+             return  registered_job 
311300
312301        if  function .function_class  ==  FunctionClass .SOLVER :
313302            solver_job  =  await  self ._job_service .create_solver_job (
@@ -325,20 +314,22 @@ async def run_function(
325314                job_id = solver_job .id ,
326315                pricing_spec = pricing_spec ,
327316            )
328-             registered_jobs  =  await  self .patch_registered_function_job (
317+             registered_job  =  await  self . _web_rpc_client .patch_registered_function_job (
329318                user_id = self .user_id ,
330319                product_name = self .product_name ,
331-                 patches = [
332-                     FunctionJobPatch (
333-                         function_class = FunctionClass .SOLVER ,
334-                         function_job_id = pre_registered_function_job_data .function_job_id ,
320+                 function_job_patch_request = FunctionJobPatchRequest (
321+                     uid = pre_registered_function_job_data .function_job_id ,
322+                     patch = RegisteredSolverFunctionJobPatch (
323+                         title = None ,
324+                         description = None ,
325+                         inputs = None ,
326+                         outputs = None ,
335327                        job_creation_task_id = None ,
336328                        solver_job_id = solver_job .id ,
337-                     )
338-                 ] ,
329+                     ), 
330+                 ) ,
339331            )
340-             assert  len (registered_jobs ) ==  1 
341-             return  registered_jobs [0 ]
332+             return  registered_job 
342333
343334        raise  UnsupportedFunctionClassError (
344335            function_class = function .function_class ,
0 commit comments