From 8e8d39903263bb3c0a87be22a6d233bb75e5a498 Mon Sep 17 00:00:00 2001 From: Hristo Date: Fri, 28 Jul 2023 14:43:53 -0400 Subject: [PATCH 1/3] checkpoint for node init params injection --- flojoy/flojoy_python.py | 2 +- flojoy/node_init.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/flojoy/flojoy_python.py b/flojoy/flojoy_python.py index e8fe0b4..2288918 100644 --- a/flojoy/flojoy_python.py +++ b/flojoy/flojoy_python.py @@ -196,7 +196,7 @@ def wrapper( # check if node has an init container and if so, inject it if NodeInitService().has_init_store(node_id): - args["init_container"] = NodeInitService().get_init_store(node_id) + args["flojoy_init_input"] = NodeInitService().get_init_store(node_id).get() ########################## # calling the node function diff --git a/flojoy/node_init.py b/flojoy/node_init.py index 8e779c2..65786b0 100644 --- a/flojoy/node_init.py +++ b/flojoy/node_init.py @@ -1,4 +1,7 @@ -from typing import Callable +from inspect import signature +from typing import Any, Callable + +from flojoy.parameter_types import format_param_value from .dao import Dao @@ -25,9 +28,19 @@ def __init__(self, func): def __call__(self, node_id: str): return self.run(node_id) - def run(self, node_id: str): + def run(self, node_id: str, ctrls: dict[str, Any] | None = None): daemon_container = NodeInitService().create_init_store(node_id) - res = self.func() + args = {} + # -- get ctrls to inject into init function -- + parameters = signature(self.func).parameters + if ctrls is not None: + for _, input in ctrls.items(): + param = input["param"] + value = input["value"] + if param in parameters: + args[param] = format_param_value(value, input["type"]) + # -------------------------------------------- + res = self.func(**args) if res is not None: daemon_container.set(res) From 76c154c292b7b2e7df974946bdf3ca4ad5fc71f9 Mon Sep 17 00:00:00 2001 From: Hristo Date: Fri, 28 Jul 2023 18:08:56 -0400 Subject: [PATCH 2/3] go back to injecting node container instead --- flojoy/flojoy_python.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flojoy/flojoy_python.py b/flojoy/flojoy_python.py index 2288918..7f1f2a8 100644 --- a/flojoy/flojoy_python.py +++ b/flojoy/flojoy_python.py @@ -196,7 +196,7 @@ def wrapper( # check if node has an init container and if so, inject it if NodeInitService().has_init_store(node_id): - args["flojoy_init_input"] = NodeInitService().get_init_store(node_id).get() + args["flojoy_init_input"] = NodeInitService().get_init_store(node_id) ########################## # calling the node function From ed992fed3b3041cfe21d96cecf91710ae2e1967a Mon Sep 17 00:00:00 2001 From: Hristo Date: Fri, 28 Jul 2023 18:59:40 -0400 Subject: [PATCH 3/3] format --- flojoy/flojoy_python.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/flojoy/flojoy_python.py b/flojoy/flojoy_python.py index 7f1f2a8..95c6df6 100644 --- a/flojoy/flojoy_python.py +++ b/flojoy/flojoy_python.py @@ -196,7 +196,9 @@ def wrapper( # check if node has an init container and if so, inject it if NodeInitService().has_init_store(node_id): - args["flojoy_init_input"] = NodeInitService().get_init_store(node_id) + args["flojoy_init_input"] = NodeInitService().get_init_store( + node_id + ) ########################## # calling the node function