v1 server and lifecycle manager working. execution contract added
This commit is contained in:
+55
@@ -0,0 +1,55 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user