From 56a67d90a7469012a69655ae9d51cfd193ea6984 Mon Sep 17 00:00:00 2001 From: Zhongyue Luo Date: Tue, 1 Jul 2014 11:02:51 +0800 Subject: [PATCH] Changes calcuation of variable delay In the loopingcall.FixedIntervalLoopingCall class, an warning is logged when 'delay' is equal or less than zero. Commonly delayed time is considered something over due from a deadline which is a positive value. Also a task delayed zero seconds is not considered delayed but finished on time. Therefore this patch fixes the calculation of the variable 'delay' and omits a warning log when 'delay' is zero Change-Id: I9dbae0838e6c03fa0eaa79e7332e650b02ed9c77 --- openstack/common/loopingcall.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openstack/common/loopingcall.py b/openstack/common/loopingcall.py index f9e1386..862f8b9 100644 --- a/openstack/common/loopingcall.py +++ b/openstack/common/loopingcall.py @@ -82,12 +82,12 @@ class FixedIntervalLoopingCall(LoopingCallBase): end = _ts() if not self._running: break - delay = interval + start - end - if delay <= 0: + delay = end - start - interval + if delay > 0: LOG.warn(_LW('task %(func_name)s run outlasted ' 'interval by %(delay).2f sec'), - {'func_name': repr(self.f), 'delay': -delay}) - greenthread.sleep(delay if delay > 0 else 0) + {'func_name': repr(self.f), 'delay': delay}) + greenthread.sleep(-delay if delay < 0 else 0) except LoopingCallDone as e: self.stop() done.send(e.retvalue)