Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
 - add logging functionality to PlanMonitor and PlanDispatcher
 - bugfix processing execution result
 - bugfix in robot_example.py
  • Loading branch information
franklinselva committed Sep 22, 2023
1 parent 8e9e561 commit 8667ab2
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion examples/robot_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def main():
print("*" * 10)

graph_executor = bridge.get_executable_graph(plan)
dispatcher.execute_plan(plan, graph_executor)
dispatcher.execute_plan(plan, graph_executor, dry_run=True)

print("*" * 10)
print(dispatcher.monitor_status)
Expand Down
4 changes: 2 additions & 2 deletions up_esb/execution/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def execute_action(self, task_id):
# Check preconditions
result = self._check_preconditions(task_id)
if isinstance(result, Exception):
precondition_status = ConditionStatus.FAILED, result
action_status = ActionNodeStatus.FAILED, result
precondition_status = ConditionStatus.FAILED
action_status = ActionNodeStatus.FAILED
return ActionResult(precondition_status, action_status, postcondition_status, result)
elif result:
precondition_status = ConditionStatus.SUCCEEDED
Expand Down
9 changes: 6 additions & 3 deletions up_esb/plexmo/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from up_esb.exceptions import UPESBException, UPESBWarning
from up_esb.execution import ActionExecutor, ActionResult
from up_esb.logger import Logger
from up_esb.status import ActionNodeStatus, ConditionStatus, DispatcherStatus, MonitorStatus

from .monitor import PlanMonitor
Expand All @@ -35,13 +36,14 @@ def __init__(self):
self._graph = None
self._status = DispatcherStatus.IDLE
self._dispatch_cb = self._default_dispatch_cb
self._replan_cb = self._default_replan_cb
self._replan_cb = None
self._options = None
self._executor = None
self._plan = None
self._rules = {}
self._monitor = None
self._node_data = None
self._logger = Logger(__name__)

@property
def monitor(self) -> PlanMonitor:
Expand Down Expand Up @@ -113,9 +115,10 @@ def execute_plan(self, plan: Plan, graph: nx.DiGraph, **options):
self._monitor.update_action_status(node_id, ActionNodeStatus.NOT_STARTED)
self._status = DispatcherStatus.FAILED

message = f"Predecessors for action {node['node_name']} are not succeeded. Cannot execute the action."
message = f"Predecessors for action {node['node_name']} are not succeeded. Cannot execute the action. Exiting..."
if options.get("dry_run", False):
raise UPESBException(message)
self._logger.warning(message)
exit(1)
raise UPESBWarning(message)

# Execute the action
Expand Down
4 changes: 3 additions & 1 deletion up_esb/plexmo/monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

from up_esb.exceptions import process_action_result
from up_esb.execution import ActionResult
from up_esb.logger import Logger
from up_esb.status import ActionNodeStatus, MonitorStatus


Expand All @@ -32,6 +33,7 @@ def __init__(self, executable_graph: nx.DiGraph):
self._graph = executable_graph
self._status = MonitorStatus.IDLE
self._action_status = ActionNodeStatus.NOT_STARTED
self._logger = Logger(__name__)

# Preprocess the graph to remove the executable elements.
self._preprocess_graph()
Expand Down Expand Up @@ -103,4 +105,4 @@ def process_action_result(self, result: ActionResult, dry_run: bool = False) ->
else:
# Reraise as warning
exception = process_action_result(result)
raise Warning(str(exception))
self._logger.warning(str(exception))

0 comments on commit 8667ab2

Please sign in to comment.