From 615d76910388d3590ad77e9cfce7ded421b060c0 Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Fri, 16 Nov 2012 15:17:52 +0000 Subject: Account for tasks duration in LoopingCall delay Fixes bug 1079725 Previously the time spent executing tasks was not accounted for when determining how much time to sleep between task runs. Now we subtract the duration of the last tasks run from the next sleep interval. Change-Id: I4b3e27d4aaa21d020159d46eea40bdd80361cea7 --- openstack/common/loopingcall.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'openstack/common/loopingcall.py') diff --git a/openstack/common/loopingcall.py b/openstack/common/loopingcall.py index 1d34519..be044d8 100644 --- a/openstack/common/loopingcall.py +++ b/openstack/common/loopingcall.py @@ -24,6 +24,7 @@ from eventlet import greenthread from openstack.common.gettextutils import _ from openstack.common import log as logging +from openstack.common import timeutils LOG = logging.getLogger(__name__) @@ -62,10 +63,16 @@ class LoopingCall(object): try: while self._running: + start = timeutils.utcnow() self.f(*self.args, **self.kw) + end = timeutils.utcnow() if not self._running: break - greenthread.sleep(interval) + delay = interval - timeutils.delta_seconds(start, end) + if delay <= 0: + LOG.warn(_('task run outlasted interval by %s sec') % + -delay) + greenthread.sleep(delay if delay > 0 else 0) except LoopingCallDone, e: self.stop() done.send(e.retvalue) -- cgit