loopingcall

loopingcall

class oslo_service.loopingcall.BackOffLoopingCall(f=None, *args, **kw)

Bases: oslo_service.loopingcall.LoopingCallBase

Run a method in a loop with backoff on error.

The passed in function should return True (no error, return to initial_interval), False (error, start backing off), or raise LoopingCallDone(retvalue=None) (quit looping, return retvalue if set).

When there is an error, the call will backoff on each failure. The backoff will be equal to double the previous base interval times some jitter. If a backoff would put it over the timeout, it halts immediately, so the call will never take more than timeout, but may and likely will take less time.

When the function return value is True or False, the interval will be multiplied by a random jitter. If min_jitter or max_jitter is None, there will be no jitter (jitter=1). If min_jitter is below 0.5, the code may not backoff and may increase its retry rate.

If func constantly returns True, this function will not return.

To run a func and wait for a call to finish (by raising a LoopingCallDone):

timer = BackOffLoopingCall(func) response = timer.start().wait()
Parameters:
  • initial_delay – delay before first running of function
  • starting_interval – initial interval in seconds between calls to function. When an error occurs and then a success, the interval is returned to starting_interval
  • timeout – time in seconds before a LoopingCallTimeout is raised. The call will never take longer than timeout, but may quit before timeout.
  • max_interval – The maximum interval between calls during errors
  • jitter – Used to vary when calls are actually run to avoid group of calls all coming at the exact same time. Uses random.gauss(jitter, 0.1), with jitter as the mean for the distribution. If set below .5, it can cause the calls to come more rapidly after each failure.
  • min_interval – The minimum interval in seconds between calls to function.
Raises:

LoopingCallTimeout if time spent doing error retries would exceed timeout.

start(initial_delay=None, starting_interval=1, timeout=300, max_interval=300, jitter=0.75, min_interval=0.001)
class oslo_service.loopingcall.DynamicLoopingCall(f=None, *args, **kw)

Bases: oslo_service.loopingcall.LoopingCallBase

A looping call which sleeps until the next known event.

The function called should return how long to sleep for before being called again.

start(initial_delay=None, periodic_interval_max=None, stop_on_exception=True)
class oslo_service.loopingcall.FixedIntervalLoopingCall(f=None, *args, **kw)

Bases: oslo_service.loopingcall.LoopingCallBase

A fixed interval looping call.

start(interval, initial_delay=None, stop_on_exception=True)
class oslo_service.loopingcall.FixedIntervalWithTimeoutLoopingCall(f=None, *args, **kw)

Bases: oslo_service.loopingcall.LoopingCallBase

A fixed interval looping call with timeout checking mechanism.

start(interval, initial_delay=None, stop_on_exception=True, timeout=0)
class oslo_service.loopingcall.LoopingCallBase(f=None, *args, **kw)

Bases: object

stop()
wait()
exception oslo_service.loopingcall.LoopingCallDone(retvalue=True)

Bases: exceptions.Exception

Exception to break out and stop a LoopingCallBase.

The poll-function passed to LoopingCallBase 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 LoopingCallBase.wait()

exception oslo_service.loopingcall.LoopingCallTimeOut

Bases: exceptions.Exception

Exception for a timed out LoopingCall.

The LoopingCall will raise this exception when a timeout is provided and it is exceeded.

class oslo_service.loopingcall.RetryDecorator(max_retry_count=-1, inc_sleep_time=10, max_sleep_time=60, exceptions=())

Bases: object

Decorator for retrying a function upon suggested exceptions.

The decorated function is retried for the given number of times, and the sleep time between the retries is incremented until max sleep time is reached. If the max retry count is set to -1, then the decorated function is invoked indefinitely until an exception is thrown, and the caught exception is not in the list of suggested exceptions.

Creative Commons Attribution 3.0 License

Except where otherwise noted, this document is licensed under Creative Commons Attribution 3.0 License. See all OpenStack Legal Documents.