summaryrefslogtreecommitdiffstats
path: root/nova/utils.py
diff options
context:
space:
mode:
authorMichael Still <mikal@stillhq.com>2013-04-09 13:25:38 +1000
committerMichael Still <mikal@stillhq.com>2013-04-16 04:24:48 +1000
commit8c53d87ad98f9b7a3ed6d4c83a6f0f62969fa64c (patch)
tree10b41290f547b4f1f3d6a8dc27c54fe862b74483 /nova/utils.py
parent36b10384724fec9657784980cd2bd38e72b445bc (diff)
downloadnova-8c53d87ad98f9b7a3ed6d4c83a6f0f62969fa64c.tar.gz
nova-8c53d87ad98f9b7a3ed6d4c83a6f0f62969fa64c.tar.xz
nova-8c53d87ad98f9b7a3ed6d4c83a6f0f62969fa64c.zip
Import and convert to oslo loopingcall.
Import the oslo looping call implementation (which is a copy of nova's), delete nova's local copy, convert all users to the new location. It should be noted that the oslo implementation of FixedIntervalLoopingCall measures time from the start of the periodic task, not the end, so periodic tasks will run with a constant frequency instead of the frequency changing depending on how long the periodic task takes to run. Change-Id: Ia62ce1988f5373c09146efa6b3b1d1dc094d50c4
Diffstat (limited to 'nova/utils.py')
-rw-r--r--nova/utils.py108
1 files changed, 0 insertions, 108 deletions
diff --git a/nova/utils.py b/nova/utils.py
index 7a586c322..bb002b9e7 100644
--- a/nova/utils.py
+++ b/nova/utils.py
@@ -38,7 +38,6 @@ import tempfile
import time
from xml.sax import saxutils
-from eventlet import event
from eventlet.green import subprocess
from eventlet import greenthread
import netaddr
@@ -547,113 +546,6 @@ class LazyPluggable(object):
return getattr(backend, key)
-class LoopingCallDone(Exception):
- """Exception to break out and stop a LoopingCall.
-
- The poll-function passed to LoopingCall can raise this exception to
- break out of the loop normally. This is somewhat analogous to
- StopIteration.
-
- An optional return-value can be included as the argument to the exception;
- this return-value will be returned by LoopingCall.wait()
-
- """
-
- def __init__(self, retvalue=True):
- """:param retvalue: Value that LoopingCall.wait() should return."""
- self.retvalue = retvalue
-
-
-class LoopingCallBase(object):
- def __init__(self, f=None, *args, **kw):
- self.args = args
- self.kw = kw
- self.f = f
- self._running = False
- self.done = None
-
- def stop(self):
- self._running = False
-
- def wait(self):
- return self.done.wait()
-
-
-class FixedIntervalLoopingCall(LoopingCallBase):
- """A looping call which happens at a fixed interval."""
-
- def start(self, interval, initial_delay=None):
- self._running = True
- done = event.Event()
-
- def _inner():
- if initial_delay:
- greenthread.sleep(initial_delay)
-
- try:
- while self._running:
- self.f(*self.args, **self.kw)
- if not self._running:
- break
- greenthread.sleep(interval)
- except LoopingCallDone, e:
- self.stop()
- done.send(e.retvalue)
- except Exception:
- LOG.exception(_('in fixed duration looping call'))
- done.send_exception(*sys.exc_info())
- return
- else:
- done.send(True)
-
- self.done = done
-
- greenthread.spawn(_inner)
- return self.done
-
-
-class DynamicLoopingCall(LoopingCallBase):
- """A looping call which happens sleeps until the next known event.
-
- The function called should return how long to sleep for before being
- called again.
- """
-
- def start(self, initial_delay=None, periodic_interval_max=None):
- self._running = True
- done = event.Event()
-
- def _inner():
- if initial_delay:
- greenthread.sleep(initial_delay)
-
- try:
- while self._running:
- idle = self.f(*self.args, **self.kw)
- if not self._running:
- break
-
- if periodic_interval_max is not None:
- idle = min(idle, periodic_interval_max)
- LOG.debug(_('Periodic task processor sleeping for %.02f '
- 'seconds'), idle)
- greenthread.sleep(idle)
- except LoopingCallDone, e:
- self.stop()
- done.send(e.retvalue)
- except Exception:
- LOG.exception(_('in dynamic looping call'))
- done.send_exception(*sys.exc_info())
- return
- else:
- done.send(True)
-
- self.done = done
-
- greenthread.spawn(_inner)
- return self.done
-
-
def xhtml_escape(value):
"""Escapes a string so it is valid within XML or XHTML.