From 66fc2df3a61198df8d9b3acf1ac9fed6b87ae060 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 23 Jan 2015 14:45:24 -0800 Subject: [PATCH] Add comments to runner state machine reaction functions To make it a little more obvious what each function is responsible for doing (and why) add comments onto each inner reaction function that explains more of its purpose in life. Change-Id: Ibdb55e873e4b1ae5675e2f50d85ac0ecbd59ffb6 --- taskflow/engines/action_engine/runner.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/taskflow/engines/action_engine/runner.py b/taskflow/engines/action_engine/runner.py index a5bebd61..f1f880ce 100644 --- a/taskflow/engines/action_engine/runner.py +++ b/taskflow/engines/action_engine/runner.py @@ -99,11 +99,19 @@ class _MachineBuilder(object): timeout = _WAITING_TIMEOUT def resume(old_state, new_state, event): + # This reaction function just updates the state machines memory + # to include any nodes that need to be executed (from a previous + # attempt, which may be empty if never ran before) and any nodes + # that are now ready to be ran. memory.next_nodes.update(self._completer.resume()) memory.next_nodes.update(self._analyzer.get_next_nodes()) return _SCHEDULE def game_over(old_state, new_state, event): + # This reaction function is mainly a intermediary delegation + # function that analyzes the current memory and transitions to + # the appropriate handler that will deal with the memory values, + # it is *always* called before the final state is entered. if memory.failures: return _FAILED if self._analyzer.get_next_nodes(): @@ -114,6 +122,11 @@ class _MachineBuilder(object): return _REVERTED def schedule(old_state, new_state, event): + # This reaction function starts to schedule the memory's next + # nodes (iff the engine is still runnable, which it may not be + # if the user of this engine has requested the engine/storage + # that holds this information to stop or suspend); handles failures + # that occur during this process safely... if self.runnable() and memory.next_nodes: not_done, failures = self._scheduler.schedule( memory.next_nodes) @@ -136,6 +149,11 @@ class _MachineBuilder(object): return _ANALYZE def analyze(old_state, new_state, event): + # This reaction function is responsible for analyzing all nodes + # that have finished executing and completing them and figuring + # out what nodes are now ready to be ran (and then triggering those + # nodes to be scheduled in the future); handles failures that + # occur during this process safely... next_nodes = set() while memory.done: fut = memory.done.pop()