56 lines
1.3 KiB
Python
56 lines
1.3 KiB
Python
from core.execution.action import buildAction
|
|
from core.execution.operation import buildOperation
|
|
import plugins
|
|
import importlib
|
|
import threading
|
|
from lifecyclemanager import manageLifecycle
|
|
|
|
lifecycles = {}
|
|
|
|
def buildDispatch(request):
|
|
dispatch = []
|
|
|
|
for key in request["module"]:
|
|
dispatch.append(request["module"][key])
|
|
|
|
resolveddispatch = "plugins."+ ".".join(dispatch)
|
|
|
|
module = importlib.import_module(resolveddispatch)
|
|
|
|
mode = request.get("mode", "oneshot")
|
|
|
|
if mode == "continuous":
|
|
|
|
state = {
|
|
"mode": "continuous"
|
|
}
|
|
|
|
lifecycles[resolveddispatch] = state
|
|
|
|
print(f"Dispatching: {module.name}")
|
|
|
|
thread = threading.Thread(
|
|
target=manageLifecycle,
|
|
args=(module, state)
|
|
)
|
|
|
|
thread.start()
|
|
print(f"Started lifecycle: {module.name}")
|
|
|
|
elif mode == "stop":
|
|
if resolveddispatch in lifecycles:
|
|
state = lifecycles[resolveddispatch]
|
|
state["mode"] = "stop"
|
|
print(f"Stopping lifecycle: {module.name}")
|
|
else:
|
|
print(f"No registered lifecycle: {module.name}")
|
|
|
|
elif mode == "oneshot":
|
|
outputs = manageLifecycle(module, {"mode": "oneshot"})
|
|
|
|
else:
|
|
raise ValueError(f"Unsupported lifecycle mode {mode}")
|
|
|
|
return
|
|
#outputs = manageLifecycle(module, state)
|