Fixed dispatcher and registry
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -3,3 +3,5 @@ from .runtime import buildSave, loadSave, buildLog, manageFailure, buildOutput
|
||||
#from .execution import buildOperation, buildAction
|
||||
from .execution.action import buildAction
|
||||
from .execution.operation import buildOperation
|
||||
from .execution.executioncontract import executeContract
|
||||
#from executioncontract import executionContract
|
||||
|
||||
Binary file not shown.
@@ -1,2 +1,3 @@
|
||||
#from . import action
|
||||
#from . import operation
|
||||
#from . import executioncontract
|
||||
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,9 +1,11 @@
|
||||
from core.execution.action import buildAction
|
||||
from core.execution.operation import buildOperation
|
||||
|
||||
def executeContract(module)
|
||||
if module.kind == "operation":
|
||||
outputs = buildOperation(module)
|
||||
def executeContract(module):
|
||||
if module.kind == "operation":
|
||||
outputs = buildOperation(module)
|
||||
|
||||
elif module.kind == "action":
|
||||
outputs = buildAction(module)
|
||||
elif module.kind == "action":
|
||||
outputs = buildAction(module)
|
||||
|
||||
return outputs
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import importlib
|
||||
from lifecyclemanager import manageLifecycle
|
||||
from dispatchstate import buildState
|
||||
|
||||
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")
|
||||
|
||||
return module, mode
|
||||
@@ -0,0 +1,31 @@
|
||||
import threading
|
||||
from lifecycleregistry import registerLifecycle
|
||||
from lifecyclemanager import manageLifecycle
|
||||
|
||||
activethreads = []
|
||||
threadnum = 0
|
||||
|
||||
def buildThread(module, state, lifecycles):
|
||||
#for mode in ("continuous", "oneshot")
|
||||
global threadnum
|
||||
threadnum += 1
|
||||
|
||||
threadname = f"thread.{threadnum}"
|
||||
|
||||
thread = threading.Thread(
|
||||
target=manageLifecycle,
|
||||
args=(module, state)
|
||||
)
|
||||
thread.start()
|
||||
|
||||
registryname = threadname
|
||||
registryvalue = thread
|
||||
|
||||
lifecycles = registerLifecycle (module, lifecycles, registryname, registryvalue)
|
||||
|
||||
activethreads.append(threadname)
|
||||
|
||||
print(activethreads)
|
||||
print(lifecycles)
|
||||
|
||||
return threadnum, threadname, lifecycles, activethreads
|
||||
-55
@@ -1,55 +0,0 @@
|
||||
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)
|
||||
@@ -0,0 +1,14 @@
|
||||
from createdispatch import buildDispatch
|
||||
from createthread import buildThread
|
||||
from dispatchstate import buildState
|
||||
import threading
|
||||
|
||||
def dispatchRequest(request, lifecycles):
|
||||
|
||||
module, mode = buildDispatch(request)
|
||||
|
||||
state, lifecycles = buildState(module, mode, lifecycles)
|
||||
|
||||
threadnum, threadname, lifecycles, activethreads = buildThread(module, state, lifecycles)
|
||||
|
||||
return threadnum, lifecycles,
|
||||
@@ -0,0 +1,33 @@
|
||||
import requests
|
||||
|
||||
from lifecycleregistry import registerLifecycle
|
||||
|
||||
def buildState(module, mode, lifecycles):
|
||||
registryname = "state"
|
||||
if mode == "continuous":
|
||||
registryvalue = {"mode": "continuous"}
|
||||
|
||||
lifecycles = registerLifecycle(module, lifecycles, registryname, registryvalue)
|
||||
|
||||
elif mode == "stop":
|
||||
if not module.name in lifecycles:
|
||||
registryvalue ={}
|
||||
print(f"No registered lifecycle: {module.name}")
|
||||
return None
|
||||
elif lifecycles[module.name]["state"]["mode"] != "stop":
|
||||
state = lifecycles[module.name]["state"]
|
||||
state["mode"] = "stop"
|
||||
#lifecycles = registerLifecycle(module, lifecycles, registryname, registryvalue)
|
||||
|
||||
print(f"Stopping lifecycle: {module.name}")
|
||||
|
||||
elif mode == "oneshot":
|
||||
registryvalue = {"mode": "oneshot"}
|
||||
lifecycles = registerLifecycle(module, lifecycles, registryname, registryvalue)
|
||||
|
||||
else:
|
||||
raise ValueError(f"Unsupported lifecycle mode: {mode}")
|
||||
|
||||
state = registryvalue
|
||||
|
||||
return state, lifecycles
|
||||
+5
-9
@@ -1,16 +1,12 @@
|
||||
from core.execution.operation import buildOperation
|
||||
from core.execution.action import buildAction
|
||||
import time
|
||||
|
||||
def executeContract(module):
|
||||
if module.kind == "operation":
|
||||
outputs = buildOperation(module)
|
||||
|
||||
elif module.kind == "action":
|
||||
outputs = buildAction(module)
|
||||
|
||||
from core.execution.operation import buildOperation
|
||||
from core.execution.action import buildAction
|
||||
from core import executeContract
|
||||
|
||||
def manageLifecycle(module, state):
|
||||
print(state)
|
||||
|
||||
if state["mode"] == "continuous":
|
||||
while state["mode"] == "continuous":
|
||||
outputs = executeContract(module)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
def registerLifecycle(module, lifecycles, registryname, registryvalue):
|
||||
if module.name not in lifecycles:
|
||||
lifecycles[module.name] = {}
|
||||
|
||||
|
||||
lifecycles[module.name][registryname] = registryvalue
|
||||
|
||||
return lifecycles
|
||||
@@ -1,13 +1,17 @@
|
||||
import socket
|
||||
import json
|
||||
from dispatch import buildDispatch
|
||||
from dispatcher import dispatchRequest
|
||||
|
||||
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
server.bind(("127.0.0.1", 19001))
|
||||
server.bind(("127.0.0.1", 19002))
|
||||
|
||||
lifecycles = {}
|
||||
|
||||
server.listen()
|
||||
|
||||
#lifecycles = {}
|
||||
|
||||
while True:
|
||||
connection, address = server.accept()
|
||||
while True:
|
||||
@@ -18,7 +22,7 @@ while True:
|
||||
# if not data:
|
||||
# break
|
||||
|
||||
dispatch = buildDispatch(request)
|
||||
dispatch = dispatchRequest(request, lifecycles)
|
||||
|
||||
connection.close()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user