Rename the timing listeners to duration listeners
These listeners really only capture duration (from when the task started, to when it stopped) and are not really associated with the time a task started or when it stopped so we should rename these to be more appropriatly named. Change-Id: I54ea0fa739fcea0b3e3c155dc38ce49adfc3bb01
This commit is contained in:
@@ -163,12 +163,12 @@ Printing and logging listeners
|
|||||||
|
|
||||||
.. autoclass:: taskflow.listeners.printing.PrintingListener
|
.. autoclass:: taskflow.listeners.printing.PrintingListener
|
||||||
|
|
||||||
Timing listener
|
Timing listeners
|
||||||
---------------
|
----------------
|
||||||
|
|
||||||
.. autoclass:: taskflow.listeners.timing.TimingListener
|
.. autoclass:: taskflow.listeners.timing.DurationListener
|
||||||
|
|
||||||
.. autoclass:: taskflow.listeners.timing.PrintingTimingListener
|
.. autoclass:: taskflow.listeners.timing.PrintingDurationListener
|
||||||
|
|
||||||
Claim listener
|
Claim listener
|
||||||
--------------
|
--------------
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ from __future__ import absolute_import
|
|||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
|
from debtcollector import moves
|
||||||
|
|
||||||
from taskflow import exceptions as exc
|
from taskflow import exceptions as exc
|
||||||
from taskflow.listeners import base
|
from taskflow.listeners import base
|
||||||
from taskflow import logging
|
from taskflow import logging
|
||||||
@@ -39,7 +41,7 @@ def _printer(message):
|
|||||||
print(message)
|
print(message)
|
||||||
|
|
||||||
|
|
||||||
class TimingListener(base.Listener):
|
class DurationListener(base.Listener):
|
||||||
"""Listener that captures task duration.
|
"""Listener that captures task duration.
|
||||||
|
|
||||||
It records how long a task took to execute (or fail)
|
It records how long a task took to execute (or fail)
|
||||||
@@ -47,7 +49,7 @@ class TimingListener(base.Listener):
|
|||||||
to task metadata with key ``'duration'``.
|
to task metadata with key ``'duration'``.
|
||||||
"""
|
"""
|
||||||
def __init__(self, engine):
|
def __init__(self, engine):
|
||||||
super(TimingListener, self).__init__(engine,
|
super(DurationListener, self).__init__(engine,
|
||||||
task_listen_for=WATCH_STATES,
|
task_listen_for=WATCH_STATES,
|
||||||
flow_listen_for=[])
|
flow_listen_for=[])
|
||||||
self._timers = {}
|
self._timers = {}
|
||||||
@@ -86,22 +88,32 @@ class TimingListener(base.Listener):
|
|||||||
self._record_ending(timer, task_name)
|
self._record_ending(timer, task_name)
|
||||||
|
|
||||||
|
|
||||||
class PrintingTimingListener(TimingListener):
|
TimingListener = moves.moved_class(DurationListener,
|
||||||
"""Listener that prints the start & stop timing as well as recording it."""
|
'TimingListener', __name__,
|
||||||
|
version="0.8", removal_version="?")
|
||||||
|
|
||||||
|
|
||||||
|
class PrintingDurationListener(DurationListener):
|
||||||
|
"""Listener that prints the duration as well as recording it."""
|
||||||
|
|
||||||
def __init__(self, engine, printer=None):
|
def __init__(self, engine, printer=None):
|
||||||
super(PrintingTimingListener, self).__init__(engine)
|
super(PrintingDurationListener, self).__init__(engine)
|
||||||
if printer is None:
|
if printer is None:
|
||||||
self._printer = _printer
|
self._printer = _printer
|
||||||
else:
|
else:
|
||||||
self._printer = printer
|
self._printer = printer
|
||||||
|
|
||||||
def _record_ending(self, timer, task_name):
|
def _record_ending(self, timer, task_name):
|
||||||
super(PrintingTimingListener, self)._record_ending(timer, task_name)
|
super(PrintingDurationListener, self)._record_ending(timer, task_name)
|
||||||
self._printer("It took task '%s' %0.2f seconds to"
|
self._printer("It took task '%s' %0.2f seconds to"
|
||||||
" finish." % (task_name, timer.elapsed()))
|
" finish." % (task_name, timer.elapsed()))
|
||||||
|
|
||||||
def _task_receiver(self, state, details):
|
def _task_receiver(self, state, details):
|
||||||
super(PrintingTimingListener, self)._task_receiver(state, details)
|
super(PrintingDurationListener, self)._task_receiver(state, details)
|
||||||
if state in STARTING_STATES:
|
if state in STARTING_STATES:
|
||||||
self._printer("'%s' task started." % (details['task_name']))
|
self._printer("'%s' task started." % (details['task_name']))
|
||||||
|
|
||||||
|
|
||||||
|
PrintingTimingListener = moves.moved_class(
|
||||||
|
PrintingDurationListener, 'PrintingTimingListener', __name__,
|
||||||
|
version="0.8", removal_version="?")
|
||||||
|
|||||||
Reference in New Issue
Block a user