diff --git a/taskflow/listeners/base.py b/taskflow/listeners/base.py index 47ff8d5b..0101e8de 100644 --- a/taskflow/listeners/base.py +++ b/taskflow/listeners/base.py @@ -25,6 +25,7 @@ from taskflow import logging from taskflow import states from taskflow.types import failure from taskflow.types import notifier +from taskflow.utils import deprecation LOG = logging.getLogger(__name__) @@ -80,7 +81,7 @@ def _bulk_register(watch_states, notifier, cb, details_filter=None): return registered -class ListenerBase(object): +class Listener(object): """Base class for listeners. A listener can be attached to an engine to do various actions on flow and @@ -162,26 +163,33 @@ class ListenerBase(object): self._engine, exc_info=True) +# TODO(harlowja): remove in 0.7 or later... +ListenerBase = deprecation.moved_inheritable_class(Listener, + 'ListenerBase', __name__, + version="0.6", + removal_version="?") + + @six.add_metaclass(abc.ABCMeta) -class LoggingBase(ListenerBase): - """Abstract base class for logging listeners. +class DumpingListener(Listener): + """Abstract base class for dumping listeners. This provides a simple listener that can be attached to an engine which can - be derived from to log task and/or flow state transitions to some logging + be derived from to dump task and/or flow state transitions to some target backend. - To implement your own logging listener derive form this class and - override the ``_log`` method. + To implement your own dumping listener derive from this class and + override the ``_dump`` method. """ @abc.abstractmethod - def _log(self, message, *args, **kwargs): - """Logs the provided *templated* message to some output.""" + def _dump(self, message, *args, **kwargs): + """Dumps the provided *templated* message to some output.""" def _flow_receiver(self, state, details): - self._log("%s has moved flow '%s' (%s) into state '%s'", - self._engine, details['flow_name'], - details['flow_uuid'], state) + self._dump("%s has moved flow '%s' (%s) into state '%s'", + self._engine, details['flow_name'], + details['flow_uuid'], state) def _task_receiver(self, state, details): if state in FINISH_STATES: @@ -192,12 +200,26 @@ class LoggingBase(ListenerBase): if result.exc_info: exc_info = tuple(result.exc_info) was_failure = True - self._log("%s has moved task '%s' (%s) into state '%s'" - " with result '%s' (failure=%s)", - self._engine, details['task_name'], - details['task_uuid'], state, result, was_failure, - exc_info=exc_info) + self._dump("%s has moved task '%s' (%s) into state '%s'" + " with result '%s' (failure=%s)", + self._engine, details['task_name'], + details['task_uuid'], state, result, was_failure, + exc_info=exc_info) else: - self._log("%s has moved task '%s' (%s) into state '%s'", - self._engine, details['task_name'], - details['task_uuid'], state) + self._dump("%s has moved task '%s' (%s) into state '%s'", + self._engine, details['task_name'], + details['task_uuid'], state) + + +# TODO(harlowja): remove in 0.7 or later... +class LoggingBase(deprecation.moved_inheritable_class(DumpingListener, + 'LoggingBase', __name__, + version="0.6", + removal_version="?")): + + def _dump(self, message, *args, **kwargs): + self._log(message, *args, **kwargs) + + @abc.abstractmethod + def _log(self, message, *args, **kwargs): + """Logs the provided *templated* message to some output.""" diff --git a/taskflow/listeners/claims.py b/taskflow/listeners/claims.py index 3fbc15d1..7fa86474 100644 --- a/taskflow/listeners/claims.py +++ b/taskflow/listeners/claims.py @@ -27,7 +27,7 @@ from taskflow import states LOG = logging.getLogger(__name__) -class CheckingClaimListener(base.ListenerBase): +class CheckingClaimListener(base.Listener): """Listener that interacts [engine, job, jobboard]; ensures claim is valid. This listener (or a derivative) can be associated with an engines diff --git a/taskflow/listeners/logging.py b/taskflow/listeners/logging.py index d707e395..03055257 100644 --- a/taskflow/listeners/logging.py +++ b/taskflow/listeners/logging.py @@ -41,7 +41,7 @@ def _isEnabledFor(logger, level): return logger.isEnabledFor(level) -class LoggingListener(base.LoggingBase): +class LoggingListener(base.DumpingListener): """Listener that logs notifications it receives. It listens for task and flow notifications and writes those notifications @@ -65,11 +65,11 @@ class LoggingListener(base.LoggingBase): self._logger = log self._level = level - def _log(self, message, *args, **kwargs): + def _dump(self, message, *args, **kwargs): self._logger.log(self._level, message, *args, **kwargs) -class DynamicLoggingListener(base.ListenerBase): +class DynamicLoggingListener(base.Listener): """Listener that logs notifications it receives. It listens for task and flow notifications and writes those notifications diff --git a/taskflow/listeners/printing.py b/taskflow/listeners/printing.py index 719d2042..2a89b179 100644 --- a/taskflow/listeners/printing.py +++ b/taskflow/listeners/printing.py @@ -22,7 +22,7 @@ import traceback from taskflow.listeners import base -class PrintingListener(base.LoggingBase): +class PrintingListener(base.DumpingListener): """Writes the task and flow notifications messages to stdout or stderr.""" def __init__(self, engine, task_listen_for=base.DEFAULT_LISTEN_FOR, @@ -37,7 +37,7 @@ class PrintingListener(base.LoggingBase): else: self._file = sys.stdout - def _log(self, message, *args, **kwargs): + def _dump(self, message, *args, **kwargs): print(message % args, file=self._file) exc_info = kwargs.get('exc_info') if exc_info is not None: diff --git a/taskflow/listeners/timing.py b/taskflow/listeners/timing.py index f2080547..c0fab524 100644 --- a/taskflow/listeners/timing.py +++ b/taskflow/listeners/timing.py @@ -39,7 +39,7 @@ def _printer(message): print(message) -class TimingListener(base.ListenerBase): +class TimingListener(base.Listener): """Listener that captures task duration. It records how long a task took to execute (or fail)