m_strat.api.dag.executor
1from api.logger import m_log 2 3_EXECUTORS = {} 4 5 6# Defines an exectuion method for Node system. Must have (targetnodes, init_context) as arguments. Must return context 7# name muse be unique 8def Executor(name: str): 9 def decorator(func): 10 assert _EXECUTORS.get(name, None) is None, f"Executor {name} already exists" 11 _EXECUTORS[name] = func 12 return func 13 14 return decorator 15 16 17# Standard linear-non parallelised running, executes in same thread without modification 18@Executor(name="Sequential") 19def execute_sequential(target_nodes: list[tuple], init_context: dict): 20 context = init_context 21 m_log.info("Started Sequential running") 22 for func, params, node_info in target_nodes: 23 m_log.debug(f"Running Node {node_info.id}") 24 try: 25 context = func(context, params) 26 except Exception as e: 27 m_log.error( 28 f"Pipeline execution failed at '{node_info.id}' using blueprint '{node_info.blueprint_name}':\n {e}" 29 ) 30 raise e # NB you should always raise errors when making your own Executor!! 31 m_log.debug(f"Node{node_info.id} Completed") 32 33 m_log.info(f"Finished Executing {len(target_nodes)} node(s)") 34 return context
def
Executor(name: str):
@Executor(name='Sequential')
def
execute_sequential(target_nodes: list[tuple], init_context: dict):
19@Executor(name="Sequential") 20def execute_sequential(target_nodes: list[tuple], init_context: dict): 21 context = init_context 22 m_log.info("Started Sequential running") 23 for func, params, node_info in target_nodes: 24 m_log.debug(f"Running Node {node_info.id}") 25 try: 26 context = func(context, params) 27 except Exception as e: 28 m_log.error( 29 f"Pipeline execution failed at '{node_info.id}' using blueprint '{node_info.blueprint_name}':\n {e}" 30 ) 31 raise e # NB you should always raise errors when making your own Executor!! 32 m_log.debug(f"Node{node_info.id} Completed") 33 34 m_log.info(f"Finished Executing {len(target_nodes)} node(s)") 35 return context