Skip to content
This repository has been archived by the owner on Oct 10, 2023. It is now read-only.

Node init fixes #65

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion flojoy/flojoy_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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["init_container"] = NodeInitService().get_init_store(node_id)
args["flojoy_init_input"] = NodeInitService().get_init_store(
node_id
)

##########################
# calling the node function
Expand Down
19 changes: 16 additions & 3 deletions flojoy/node_init.py
Original file line number Diff line number Diff line change
@@ -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


Expand All @@ -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)

Expand Down