v1 server and lifecycle manager working. execution contract added
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
#from .managefailure import manageFailure
|
||||
#from . import outputs
|
||||
#from . import managefailure
|
||||
#from . import savedata
|
||||
from .outputs import buildOutput
|
||||
from .savedata import buildSave, loadSave
|
||||
from .logs import buildLog
|
||||
#from . import managefailure
|
||||
from .managefailure import manageFailure
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,11 @@
|
||||
def buildLog (action, outputs):
|
||||
# try:
|
||||
for print_name, print_key in action.prints.items():
|
||||
print(
|
||||
f"{print_name}:",
|
||||
f"{outputs[print_key]}",
|
||||
)
|
||||
|
||||
# except KeyError:
|
||||
#outputs[print_key] = "N/A"
|
||||
# return
|
||||
@@ -0,0 +1,19 @@
|
||||
from core.runtime.outputs import buildOutput
|
||||
from core.execution.action.action import buildAction
|
||||
#from core.runtime.outputs import buildOutput
|
||||
|
||||
def manageFailure(error, action, outputs):
|
||||
if hasattr(action, "recoverPolicy"):
|
||||
errors = action.recoverPolicy
|
||||
error_type = type(error)
|
||||
|
||||
print(f"{type(error).__name__} detected during {action.name}. Applying recovery policy.")
|
||||
|
||||
if error_type in errors:
|
||||
repairs = errors[error_type]
|
||||
|
||||
for repair in repairs:
|
||||
outputs, response = buildAction(repair, outputs)
|
||||
|
||||
return outputs
|
||||
print(f"{error}")
|
||||
@@ -0,0 +1,21 @@
|
||||
def buildOutput(response, action, outputs):
|
||||
|
||||
response_data = response.json()
|
||||
response_objects = [response_data]
|
||||
|
||||
while response_objects:
|
||||
response_object = response_objects.pop()
|
||||
|
||||
for key, value, in response_object.items():
|
||||
|
||||
if isinstance(value, dict):
|
||||
response_objects.append(value)
|
||||
|
||||
for output_name, response_key in action.outputs.items():
|
||||
if key == response_key:
|
||||
outputs[output_name] = value
|
||||
|
||||
|
||||
return outputs
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import json
|
||||
|
||||
def buildSave(outputs, action):
|
||||
save_data = {}
|
||||
|
||||
for save_name in action.savedata:
|
||||
save_data[save_name] = outputs[save_name]
|
||||
|
||||
with open(f"{action.savepath}", "w") as save_file:
|
||||
json.dump(save_data, save_file)
|
||||
|
||||
print(f"{save_name} saved by {action.name}")
|
||||
|
||||
return save_file
|
||||
|
||||
def loadSave(outputs, action):
|
||||
with open(f"{action.savepath}", "r") as save_file:
|
||||
load_data = json.load(save_file)
|
||||
|
||||
for load_name in action.loaddata:
|
||||
outputs[load_name] = load_data[load_name]
|
||||
print(f"{load_name} loaded by {action.name}")
|
||||
|
||||
return outputs
|
||||
Reference in New Issue
Block a user