Skip to content

Commit

Permalink
build inputs for serve func
Browse files Browse the repository at this point in the history
  • Loading branch information
EvangMM committed Sep 11, 2024
1 parent 08dad98 commit 16bc575
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions pkg/processor/runtime/python/py/run_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)

0 comments on commit 16bc575

Please sign in to comment.