The ironic_python_agent.backoff Module

class ironic_python_agent.backoff.BackOffLoopingCall(f=None, *args, **kw)[source]

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.
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)[source]
exception ironic_python_agent.backoff.LoopingCallTimeOut[source]

Bases: exceptions.Exception

Exception for a timed out LoopingCall.

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

Previous topic

The ironic_python_agent.api.controllers.v1.status Module

Next topic

The ironic_python_agent.cmd.agent Module

Project Source

This Page