91 lines
2.6 KiB
Python
91 lines
2.6 KiB
Python
import logging
|
|
import os
|
|
|
|
from core.runtime.stopsignals import checkDependency
|
|
from core.execution.processregistry import registerProcess
|
|
from rich.progress import track
|
|
|
|
def buildRecursive(definition, outputs):
|
|
process_log = True
|
|
recursive_log = os.environ.get("LOGS_RECURSIVE", "false").lower() == "true"
|
|
|
|
#print(outputs[definition.recursiveset["source"]])
|
|
|
|
source = outputs.get(definition.recursiveset["source"])
|
|
|
|
if source is None or source == []:
|
|
return outputs, []
|
|
|
|
outputs = registerProcess(definition, outputs)
|
|
|
|
responses = []
|
|
from core.execution.executioncontract import executeContract
|
|
recursiveset = definition.recursiveset["actions"]
|
|
|
|
source = definition.recursiveset["source"]
|
|
|
|
items = outputs.get(source)
|
|
#print(f"RECURSIVE DEBUG DURING {definition.name}")
|
|
#print(items)
|
|
|
|
#if items is None:
|
|
|
|
# if recursive_log:
|
|
# print(f"No items available in {source} for {definition.name}")
|
|
#
|
|
# return outputs, None
|
|
|
|
reverse = definition.recursiveset.get("reverse", False)
|
|
|
|
if reverse:
|
|
#print("reversing")
|
|
items = reversed(items)
|
|
|
|
for item in track(
|
|
items,
|
|
description=f"[green]{definition.name}[/green]"
|
|
):
|
|
|
|
#for item in items:
|
|
outputs[definition.recursiveset["outputlabel"]] = item
|
|
|
|
outputs["stopsignals"] = []
|
|
for job in recursiveset:
|
|
|
|
stop = checkDependency(job, outputs, definition)
|
|
|
|
#print(f"STOP SIGNAL DEBUGGING during {job.name}")
|
|
#print(outputs["stopsignals"])
|
|
#print(stop)
|
|
|
|
if stop:
|
|
#outputs["processes"][definition.name]["stopsignals"].append(job.alias)
|
|
#print("STOP SIGNAL DETECTED")
|
|
#print(f"Stopping {job.name} due to stop signal")
|
|
continue
|
|
|
|
#print(f"RECURSIVE DEBUG DURING {job.name}")
|
|
#print(item)
|
|
#outputs, response = buildAction(job, outputs)
|
|
if job.kind == "action":
|
|
outputs["processes"][definition.name][job.name] = {}
|
|
|
|
outputs, response = executeContract(job, outputs, definition)
|
|
responses.append(response)
|
|
if job.kind == "action":
|
|
outputs["processes"][definition.name][job.name]["response"] = response
|
|
|
|
outputs["processes"][definition.name]["completed"].append(job.alias)
|
|
|
|
if process_log:
|
|
logging.info(f"{definition.name} completed")
|
|
|
|
retain = definition.recursiveset.get("retain", True)
|
|
|
|
if not retain:
|
|
outputs.pop(source, None)
|
|
|
|
outputs.pop("stopsignals", None)
|
|
|
|
return outputs, responses
|