From 018dbf628d472222f6b89d9bf8f227e8f8cd68f9 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Tue, 24 Mar 2015 13:21:13 -0700 Subject: [PATCH] Have reset state handlers go through a shared list To make it hopefully easier to understand the commonality of this function and its handlers have the handlers be defined at the top of the function and use the common list in the node iteration routine when resetting/matching. Change-Id: I288eb548172b2f6f35e2bd90683f2065d3aa02dc --- taskflow/engines/action_engine/runtime.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/taskflow/engines/action_engine/runtime.py b/taskflow/engines/action_engine/runtime.py index 74d7cf4e..fc16fd9d 100644 --- a/taskflow/engines/action_engine/runtime.py +++ b/taskflow/engines/action_engine/runtime.py @@ -98,18 +98,23 @@ class Runtime(object): def reset_nodes(self, nodes, state=st.PENDING, intention=st.EXECUTE): tweaked = [] + node_state_handlers = [ + (self.task_action, {'progress': 0.0}), + (self.retry_action, {}), + ] for node in nodes: if state or intention: tweaked.append((node, state, intention)) if state: - if self.task_action.handles(node): - self.task_action.change_state(node, state, - progress=0.0) - elif self.retry_action.handles(node): - self.retry_action.change_state(node, state) - else: - raise TypeError("Unknown how to reset atom '%s' (%s)" - % (node, type(node))) + handled = False + for h, kwargs in node_state_handlers: + if h.handles(node): + h.change_state(node, state, **kwargs) + handled = True + break + if not handled: + raise TypeError("Unknown how to reset state of" + " node '%s' (%s)" % (node, type(node))) if intention: self.storage.set_atom_intention(node.name, intention) return tweaked