Move atom action handlers to there own subfolder/submodule
Since action handlers are atom specific it seems appropriate to place the handlers under a specific submodule so that the action engine module/folder layout is more obvious and makes more sense. This also adds on a handles(atom) method to those handlers so that the runtime module/class can use those methods to determine which handler should handle resetting an atom to its initial state. Change-Id: I7067d91347b41613fba1492d81d68a590f22c467
This commit is contained in:
0
taskflow/engines/action_engine/actions/__init__.py
Normal file
0
taskflow/engines/action_engine/actions/__init__.py
Normal file
@@ -17,7 +17,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from taskflow.engines.action_engine import executor as ex
|
from taskflow.engines.action_engine import executor as ex
|
||||||
from taskflow import retry as rt
|
from taskflow import retry as retry_atom
|
||||||
from taskflow import states
|
from taskflow import states
|
||||||
from taskflow.types import failure
|
from taskflow.types import failure
|
||||||
from taskflow.types import futures
|
from taskflow.types import futures
|
||||||
@@ -28,19 +28,25 @@ SAVE_RESULT_STATES = (states.SUCCESS, states.FAILURE)
|
|||||||
|
|
||||||
|
|
||||||
class RetryAction(object):
|
class RetryAction(object):
|
||||||
|
"""An action that handles executing, state changes, ... of retry atoms."""
|
||||||
|
|
||||||
def __init__(self, storage, notifier, walker_factory):
|
def __init__(self, storage, notifier, walker_factory):
|
||||||
self._storage = storage
|
self._storage = storage
|
||||||
self._notifier = notifier
|
self._notifier = notifier
|
||||||
self._walker_factory = walker_factory
|
self._walker_factory = walker_factory
|
||||||
self._executor = futures.SynchronousExecutor()
|
self._executor = futures.SynchronousExecutor()
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def handles(atom):
|
||||||
|
return isinstance(atom, retry_atom.Retry)
|
||||||
|
|
||||||
def _get_retry_args(self, retry, addons=None):
|
def _get_retry_args(self, retry, addons=None):
|
||||||
scope_walker = self._walker_factory(retry)
|
scope_walker = self._walker_factory(retry)
|
||||||
kwargs = self._storage.fetch_mapped_args(retry.rebind,
|
kwargs = self._storage.fetch_mapped_args(retry.rebind,
|
||||||
atom_name=retry.name,
|
atom_name=retry.name,
|
||||||
scope_walker=scope_walker)
|
scope_walker=scope_walker)
|
||||||
history = self._storage.get_retry_history(retry.name)
|
history = self._storage.get_retry_history(retry.name)
|
||||||
kwargs[rt.EXECUTE_REVERT_HISTORY] = history
|
kwargs[retry_atom.EXECUTE_REVERT_HISTORY] = history
|
||||||
if addons:
|
if addons:
|
||||||
kwargs.update(addons)
|
kwargs.update(addons)
|
||||||
return kwargs
|
return kwargs
|
||||||
@@ -103,7 +109,7 @@ class RetryAction(object):
|
|||||||
|
|
||||||
self.change_state(retry, states.REVERTING)
|
self.change_state(retry, states.REVERTING)
|
||||||
arg_addons = {
|
arg_addons = {
|
||||||
rt.REVERT_FLOW_FAILURES: self._storage.get_failures(),
|
retry_atom.REVERT_FLOW_FAILURES: self._storage.get_failures(),
|
||||||
}
|
}
|
||||||
fut = self._executor.submit(_execute_retry,
|
fut = self._executor.submit(_execute_retry,
|
||||||
self._get_retry_args(retry,
|
self._get_retry_args(retry,
|
||||||
@@ -17,6 +17,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from taskflow import states
|
from taskflow import states
|
||||||
|
from taskflow import task as task_atom
|
||||||
from taskflow.types import failure
|
from taskflow.types import failure
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
@@ -25,6 +26,7 @@ SAVE_RESULT_STATES = (states.SUCCESS, states.FAILURE)
|
|||||||
|
|
||||||
|
|
||||||
class TaskAction(object):
|
class TaskAction(object):
|
||||||
|
"""An action that handles scheduling, state changes, ... of task atoms."""
|
||||||
|
|
||||||
def __init__(self, storage, task_executor, notifier, walker_factory):
|
def __init__(self, storage, task_executor, notifier, walker_factory):
|
||||||
self._storage = storage
|
self._storage = storage
|
||||||
@@ -32,6 +34,10 @@ class TaskAction(object):
|
|||||||
self._notifier = notifier
|
self._notifier = notifier
|
||||||
self._walker_factory = walker_factory
|
self._walker_factory = walker_factory
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def handles(atom):
|
||||||
|
return isinstance(atom, task_atom.BaseTask)
|
||||||
|
|
||||||
def _is_identity_transition(self, state, task, progress):
|
def _is_identity_transition(self, state, task, progress):
|
||||||
if state in SAVE_RESULT_STATES:
|
if state in SAVE_RESULT_STATES:
|
||||||
# saving result is never identity transition
|
# saving result is never identity transition
|
||||||
@@ -14,16 +14,14 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
from taskflow.engines.action_engine.actions import retry as ra
|
||||||
|
from taskflow.engines.action_engine.actions import task as ta
|
||||||
from taskflow.engines.action_engine import analyzer as an
|
from taskflow.engines.action_engine import analyzer as an
|
||||||
from taskflow.engines.action_engine import completer as co
|
from taskflow.engines.action_engine import completer as co
|
||||||
from taskflow.engines.action_engine import retry_action as ra
|
|
||||||
from taskflow.engines.action_engine import runner as ru
|
from taskflow.engines.action_engine import runner as ru
|
||||||
from taskflow.engines.action_engine import scheduler as sched
|
from taskflow.engines.action_engine import scheduler as sched
|
||||||
from taskflow.engines.action_engine import scopes as sc
|
from taskflow.engines.action_engine import scopes as sc
|
||||||
from taskflow.engines.action_engine import task_action as ta
|
|
||||||
from taskflow import retry as retry_atom
|
|
||||||
from taskflow import states as st
|
from taskflow import states as st
|
||||||
from taskflow import task as task_atom
|
|
||||||
from taskflow.utils import misc
|
from taskflow.utils import misc
|
||||||
|
|
||||||
|
|
||||||
@@ -93,9 +91,10 @@ class Runtime(object):
|
|||||||
def reset_nodes(self, nodes, state=st.PENDING, intention=st.EXECUTE):
|
def reset_nodes(self, nodes, state=st.PENDING, intention=st.EXECUTE):
|
||||||
for node in nodes:
|
for node in nodes:
|
||||||
if state:
|
if state:
|
||||||
if isinstance(node, task_atom.BaseTask):
|
if self.task_action.handles(node):
|
||||||
self.task_action.change_state(node, state, progress=0.0)
|
self.task_action.change_state(node, state,
|
||||||
elif isinstance(node, retry_atom.Retry):
|
progress=0.0)
|
||||||
|
elif self.retry_action.handles(node):
|
||||||
self.retry_action.change_state(node, state)
|
self.retry_action.change_state(node, state)
|
||||||
else:
|
else:
|
||||||
raise TypeError("Unknown how to reset atom '%s' (%s)"
|
raise TypeError("Unknown how to reset atom '%s' (%s)"
|
||||||
|
|||||||
Reference in New Issue
Block a user