diff --git a/taskflow/engines/action_engine/engine.py b/taskflow/engines/action_engine/engine.py index 730d2895..5a0fc9fb 100644 --- a/taskflow/engines/action_engine/engine.py +++ b/taskflow/engines/action_engine/engine.py @@ -217,7 +217,7 @@ class ActionEngine(base.EngineBase): self._compilation = self._compiler.compile() self._runtime = runtime.Runtime(self._compilation, self.storage, - self.task_notifier, + self.atom_notifier, self._task_executor) self._compiled = True diff --git a/taskflow/engines/action_engine/runtime.py b/taskflow/engines/action_engine/runtime.py index 06959f29..9e053a47 100644 --- a/taskflow/engines/action_engine/runtime.py +++ b/taskflow/engines/action_engine/runtime.py @@ -36,8 +36,8 @@ class Runtime(object): action engine to run to completion. """ - def __init__(self, compilation, storage, task_notifier, task_executor): - self._task_notifier = task_notifier + def __init__(self, compilation, storage, atom_notifier, task_executor): + self._atom_notifier = atom_notifier self._task_executor = task_executor self._storage = storage self._compilation = compilation @@ -68,7 +68,7 @@ class Runtime(object): @misc.cachedproperty def retry_action(self): - return ra.RetryAction(self._storage, self._task_notifier, + return ra.RetryAction(self._storage, self._atom_notifier, lambda atom: sc.ScopeWalker(self.compilation, atom, names_only=True)) @@ -76,7 +76,7 @@ class Runtime(object): @misc.cachedproperty def task_action(self): return ta.TaskAction(self._storage, self._task_executor, - self._task_notifier, + self._atom_notifier, lambda atom: sc.ScopeWalker(self.compilation, atom, names_only=True)) diff --git a/taskflow/engines/base.py b/taskflow/engines/base.py index 2fab9d0f..2c409726 100644 --- a/taskflow/engines/base.py +++ b/taskflow/engines/base.py @@ -20,6 +20,7 @@ import abc import six from taskflow.types import notifier +from taskflow.utils import deprecation from taskflow.utils import misc @@ -31,6 +32,10 @@ class EngineBase(object): occur related to the flow the engine contains. :ivar task_notifier: A notification object that will dispatch events that occur related to the tasks the engine contains. + occur related to the tasks the engine + contains (deprecated). + :ivar atom_notifier: A notification object that will dispatch events that + occur related to the atoms the engine contains. """ def __init__(self, flow, flow_detail, backend, options): @@ -41,8 +46,25 @@ class EngineBase(object): self._options = {} else: self._options = dict(options) - self.notifier = notifier.Notifier() - self.task_notifier = notifier.Notifier() + self._notifier = notifier.Notifier() + self._atom_notifier = notifier.Notifier() + + @property + def notifier(self): + """The flow notifier.""" + return self._notifier + + @property + @deprecation.moved_property('atom_notifier', version="0.6", + removal_version="?") + def task_notifier(self): + """The task notifier.""" + return self._atom_notifier + + @property + def atom_notifier(self): + """The atom notifier.""" + return self._atom_notifier @property def options(self): diff --git a/taskflow/utils/deprecation.py b/taskflow/utils/deprecation.py index 899e035d..7e8e60bc 100644 --- a/taskflow/utils/deprecation.py +++ b/taskflow/utils/deprecation.py @@ -14,8 +14,11 @@ # License for the specific language governing permissions and limitations # under the License. +import functools import warnings +import six + from taskflow.utils import reflection @@ -92,17 +95,10 @@ class MovedClassProxy(object): type(self).__name__, id(self), wrapped, id(wrapped)) -def moved_class(new_class, old_class_name, old_module_name, message=None, - version=None, removal_version=None): - """Deprecates a class that was moved to another location. - - This will emit warnings when the old locations class is initialized, - telling where the new and improved location for the old class now is. - """ - old_name = ".".join((old_module_name, old_class_name)) - new_name = reflection.get_class_name(new_class) +def _generate_moved_message(kind, old_name, new_name, + message=None, version=None, removal_version=None): message_components = [ - "Class '%s' has moved to '%s'" % (old_name, new_name), + "%s '%s' has moved to '%s'" % (kind, old_name, new_name), ] if version: message_components.append(" in version '%s'" % version) @@ -115,4 +111,54 @@ def moved_class(new_class, old_class_name, old_module_name, message=None, % removal_version) if message: message_components.append(": %s" % message) - return MovedClassProxy(new_class, "".join(message_components), 3) + return ''.join(message_components) + + +def _moved_decorator(kind, new_attribute_name, message=None, + version=None, removal_version=None): + """Decorates a method/property that was moved to another location.""" + + def decorator(f): + try: + old_attribute_name = f.__qualname__ + fully_qualified = True + except AttributeError: + old_attribute_name = f.__name__ + fully_qualified = False + + @six.wraps(f) + def wrapper(self, *args, **kwargs): + base_name = reflection.get_class_name(self, fully_qualified=False) + if fully_qualified: + old_name = old_attribute_name + else: + old_name = ".".join((base_name, old_attribute_name)) + new_name = ".".join((base_name, new_attribute_name)) + out_message = _generate_moved_message( + kind, old_name=old_name, new_name=new_name, message=message, + version=version, removal_version=removal_version) + deprecation(out_message, 3) + return f(self, *args, **kwargs) + + return wrapper + + return decorator + + +"""Decorates a *instance* property that was moved to another location.""" +moved_property = functools.partial(_moved_decorator, 'Property') + + +def moved_class(new_class, old_class_name, old_module_name, message=None, + version=None, removal_version=None): + """Deprecates a class that was moved to another location. + + This will emit warnings when the old locations class is initialized, + telling where the new and improved location for the old class now is. + """ + old_name = ".".join((old_module_name, old_class_name)) + new_name = reflection.get_class_name(new_class) + out_message = _generate_moved_message('Class', old_name, new_name, + message=message, version=version, + removal_version=removal_version) + return MovedClassProxy(new_class, out_message, 3)