From 16bc5751cf39c2174cf93576d237ddc306f51697 Mon Sep 17 00:00:00 2001 From: EvangMM Date: Wed, 11 Sep 2024 10:08:02 +0200 Subject: [PATCH] build inputs for serve func --- .../runtime/python/py/run_handler.py | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/pkg/processor/runtime/python/py/run_handler.py b/pkg/processor/runtime/python/py/run_handler.py index 2c4913c..adef013 100644 --- a/pkg/processor/runtime/python/py/run_handler.py +++ b/pkg/processor/runtime/python/py/run_handler.py @@ -112,8 +112,9 @@ def handler_job(context, event) -> Any: ############################ # Initialize ############################# + body = event.body if isinstance(event.body, bytes): - body = json.loads(event.body) + body = json.loads(body) context.logger.info(f"Received event: {body}") context.logger.info("Starting task.") @@ -200,9 +201,38 @@ def handler_serve(context, event): Any User function response. """ + ############################ + # Initialize + ############################# + body = event.body + if isinstance(event.body, bytes): + body = json.loads(body) + if body is None: + body = {} + context.logger.info(f"Received event: {body}") + + context.logger.info("Starting task.") + + ############################ + # Set inputs + ############################# + try: + context.logger.info("Configuring function inputs.") + func_args = compose_inputs( + context.run.spec.to_dict().get("inputs", {}), + context.run.spec.to_dict().get("parameters", {}), + False, + context.user_function, + context.project, + context, + event, + ) + except Exception as e: + msg = f"Something got wrong during function inputs configuration. {e.args}" + return render_error(msg, context) try: context.logger.info("Calling user function.") - return context.user_function(context, event) + return context.user_function(**func_args) except Exception as e: msg = f"Something got wrong during function execution. {e.args}" return render_error(msg, context)