From b4e4e214cb69a3f2b9d90c287dcc2dd521a7f425 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Fri, 5 Dec 2014 14:28:21 -0800 Subject: [PATCH] Remove usage of listener base postfix The base prefix added on to the listener classes is not very useful and is already understood that these are base classes by documentation or abc.ABCMeta usage so we don't need to specifically name these classes bases to also show that they are a base class (useless duplicate information). So in this change we deprecate the 'ListenerBase' and the 'LoggingBase' and rename these classes to more appropriate names. Change-Id: Iaeaeaf698c23d71720ef7b62c8781996829e192a --- taskflow/listeners/base.py | 60 +++++++++++++++++++++++----------- taskflow/listeners/claims.py | 2 +- taskflow/listeners/logging.py | 6 ++-- taskflow/listeners/printing.py | 4 +-- taskflow/listeners/timing.py | 2 +- 5 files changed, 48 insertions(+), 26 deletions(-) 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)