Commit Graph

35 Commits

Author SHA1 Message Date
Julia Kreger d3ee8ef00a Fix BackOffLoopingCall error so it is not misleading
The backoff looping call logging was previously making
a decision on if timeout had or was going to be exceeded
by including idle time and it's internal time, however
this is misleading as the overall operation may take
30 seconds externally, a user initiated timeout of 30
seconds is requested, and the error might say something
like 18 seconds has passed, when that is incorrect.

The logic is actualy correct, the logging was just
misleading.

Fixes the exception message to use the total time.

Change-Id: Ie9ef5a53abb24f6ab7de0ad57a672c0a8d7ff0ee
2021-09-16 10:18:35 -07:00
Hervé Beraud d08727effa Drop six usages
Support of python 2.7 was dropped during the Ussuri cycle so we can now
drop six usages too.

Change-Id: I56a9c0641fd9bce613943ff938d33178d263eedf
2020-05-26 15:20:01 +02:00
Ben Nemec 4c0d4490e8 Use eventletutils Event class
Instead of having a copy-pasted version in this project, let's just
use the original directly. It is added to the public API of
oslo.utils in the dependency.

Depends-On: https://review.openstack.org/614806
Change-Id: If0dfac2505d097c117ef94c99399b1614f1e1f8f
2019-01-10 22:06:11 +00:00
Slawek Kaplonski 3e08f3375e Fix stop of loopingcall
Patch [1] for switched to use eventlet Event for loopingcall events.

It may now happen that stop event is sent when other event was
already sent and loopingcall is already not running.
That cause AssertionError in eventlet.event module.

To avoid that, we should check if if loopingcall is
running before sending _abort.set().

[1] https://review.openstack.org/#/c/611807/

Closes-Bug #1800879

Change-Id: I28ad3bdb51a20350c90dee4420058c30946897e5
2018-10-31 23:19:17 +01:00
Thomas Herve c2463470f5 Use eventlet Event for loopingcall events
This fixes broken logic for finding out how to use green threads. Using
threading.Event with eventlet creates useless load related to timers.

Change-Id: I62e9f1a7cde8846be368fbec58b8e0825ce02079
Closes-Bug: #1798774
2018-10-22 16:36:40 +02:00
Davanum Srinivas (dims) 9091986228 Revert "Revert "Permit aborting loopingcall while sleeping""
This reverts commit 5975da493b.

Added code to support the case where unit tests are not being
monkey patched (example heat).

Change-Id: If715fbe21ac085e4f5c83cef0729dbca8dcb19ca
2018-04-13 13:53:28 -04:00
ChangBo Guo(gcb) 5975da493b Revert "Permit aborting loopingcall while sleeping"
This reverts commit ba28d511e0.

The original change breaks trove and vitrage.

Change-Id: Icb39a334b82834b592932facf93be0687563c316
2017-12-15 08:32:24 +00:00
Allain Legacy ba28d511e0 Permit aborting loopingcall while sleeping
Some of the openstack services implement worker tasks that are based on
the oslo-service LoopingCallBase objects.  They do this as a way to have
a task that runs periodically as a greenthread within a child worker
process.  For example, the neutron-server runs AgentStatusCheckWorker()
objects as base service workers in its child worker processes.

When the parent server process handles a SIGTERM signal it attempts to
stop all services launched on each of the child worker processes (i.e.,
ProcessLauncher.stop()).  That results in a stop() being called on each
of the underlying base services and then a wait() to ensure that they
complete before shutdown.

If any service that is implemented on a LoopingCallBase related object
is suspended on a greenthread.sleep() the previous call to stop() will
have no effect and so the wait() will block until the sleep() finishes.
For tasks that either have a frequent FixedLoopingBase interface or a
short initial_delay this may not be a problem, but for those with a long
delay this could mean that the wait() blocks for minutes before the
process is allowed to shutdown.

To solve this the LoopingCallBase calls to greenthread.sleep() are being
replaced with a threading.Event() object's wait() method.  This allows a
caller of stop() to interrupt the sleep and expedite the shutdown.

Closes-Bug: #1660210

Change-Id: I5835f9595826df5349e4cc8b1da8529bb960ee04
Signed-off-by: Allain Legacy <allain.legacy@windriver.com>
2017-06-02 14:18:07 -04:00
melanie witt 8f67ed7d53 Add min_interval to BackOffLoopingCall
The backoff timer has a few issues that can cause it to get stuck
in an infinite loop and never time out.

  1. The random.gauss() function used to generate random jitter can
     return negative values, so when it does, it makes the elapsed time
     self._error_time go "backward."
  2. The random jitter is used as a multiplier for the self._interval,
     so self._interval can deviate far away from the mean over time and
     walk to zero, causing self._interval to be 0, which will prevent
     the timer from making progress from that point on because idle
     will always evaluate to zero and the elapsed time won't increase.
  3. The evaluated interval doesn't have a lower bound, so over time
     it can get extremely small if jitter (the mean) < 0.5.

This adds a min_interval keyword argument to the BackOffLoopingCall
start() function that defaults to 0.001s and uses it to lower bound
the interval calculations. We'll also take the absolute value of the
return from random.gauss() to prevent elapsed time going backward, and
we'll calculate the running self._interval separately to make it track
the desired growth rate of the backoff and not let it drift with the
random.gauss() values.

Closes-Bug: #1686159

Change-Id: Id17668a34d5cedbe870c9056350a7e9c7196faa7
2017-04-25 17:13:46 +00:00
Duan Jiong d10c8fe38b Remove log translations
Log messages are no longer being translated. This removes all use of
the _LE, _LI, and _LW translation markers to simplify logging and to
avoid confusion with new contributions.

See:
http://lists.openstack.org/pipermail/openstack-i18n/2016-November/002574.html
http://lists.openstack.org/pipermail/openstack-dev/2017-March/113365.html

Change-Id: I52be02c3db254f63bb37270fa504694431d7671b
2017-03-23 16:04:59 +08:00
Wenzhi Yu d05e086b8d Add FixedIntervalWithTimeoutLoopingCall
Currently when using FixedIntervalLoopingCall, folks need to
add timeout checking logic in their function if they need it.
Adding a new class FixedIntervalWithTimeoutLoopingCall to
provide timeout checking support will save those effort.

Change-Id: I78bfb9e259c2394137d7efbc0ee96bb18a6dc5e7
2016-12-29 14:20:29 +08:00
zwei 9b82953871 Exception: message need '_' function
eventlet_backdoor.py
    loopingcall.py
    service.py

Change-Id: I41bf13a2c6afddbffe30ff36134c4a42eaa2ccf1
2016-03-09 13:07:23 +08:00
Davanum Srinivas d47ca1277f Avoid warning when time taken is close to zero
We use "%(delay).2f" to print the time taken so even
if the delay is say 0.001, we will still print the
warning. We should just round it off till the 2nd place
to avoid odd looking lines that say:

run outlasted interval by 0.00 sec

Change-Id: I7137eb7ad985d7f35adc62a65ad1218a39a7a959
2015-12-02 19:51:08 -05:00
Jenkins 34b0e79e6d Merge "Avoid the dual-naming confusion" 2015-11-18 12:51:33 +00:00
Joshua Harlow 73cfa9bb1f Avoid the dual-naming confusion
The module 'event' is an import and it is also
a function argument name in this function, this
can be confusing so rename it to be named differently
in the function.

Change-Id: I9382746f5117329b9292f811fc6a05118e76a9d0
2015-11-09 17:54:06 -08:00
Jenkins ca82d5f64c Merge "Add docstring for LoopingCallBase._start()" 2015-10-29 10:07:00 +00:00
Jenkins 50e115599e Merge "Move backoff looping call from IPA to oslo.service" 2015-10-28 07:01:02 +00:00
John L. Villalovos a430c83b23 Add docstring for LoopingCallBase._start()
And some documentation about LoopingCallBase._start()

Change-Id: I1bb38009246302883d412f3b29fd286a2b1a1a13
2015-10-22 16:18:06 -07:00
Matt Riedemann 2f649b321c RetryDecorator should not log warnings/errors for expected exceptions
The RetryDecorator is constructed with a list of expected exceptions and
if the function being retried raises an exception in that list, it is
currently logging a warning (with traceback). If there is a timeout, an
error is also logged.

This is bad practice because only the caller of the method being retried
has context as to what's going on and knows what level things should be
logged at (and if tracebacks should be logged at all).

This change drops the warning and error logging to debug level. We let
the caller handle the final re-raised exception and handle logging it at
the appropriate level and with the appropriate context for the message
to make sense to someone reading the logs rather than the somewhat
obscure messages logged within RetryDecorator.

Closes-Bug: #1503017

Change-Id: I07344aae977aca540a0555eef8d35b07bb969cbb
2015-10-05 13:20:19 -07:00
lin-hua-cheng cb7ea40e31 Move backoff looping call from IPA to oslo.service
Change-Id: Icf61e73a2b28c800b1725c8154aa3044395616e5
Depends-On: I15ae3c99267b2dd9dc9ceccd427f6c0aef6ae8da
2015-09-22 16:04:01 -07:00
Surojit Pathak fad5b04d59 Handling corner cases in dynamic looping call
If the periodic task for dynamic looping call returns no suggestion for
delay, then we should use periodic_interval_max. If
periodic_interval_max is not specified, we should raise RuntimeError.
Otherwise, passing 'None' as a value, causes Exception at eventlet's
sleep() call.

Change-Id: Ida3e75bc64132d6b5920fa94657aa962e2fe9f53
Closes-bug: #1489998
2015-08-31 22:57:53 +00:00
liu-sheng bbfcde1737 Change DEBUG log in loopingcall to TRACE level log
The DEBUG log message in _run_loop() method will record every
loopingcall info every interval, that may cause log noise. e.g. In
ceilometer, the partition coordinator will have a fixed interval looping
call every two seconds as default.

Change-Id: I32aa474ece2458aa7cc1a5c271a40f664bf07af2
2015-08-27 09:06:19 +00:00
Joshua Harlow 9f624f7405 Use oslo_utils reflection to get 'f' callable name
Using the utility function gets a better name.

For example:

$ python

>>> from oslo_utils import reflection
>>> class A(object):
...   def m(self):
...     pass
...
>>> z = A()
>>> reflection.get_callable_name(z.m)
'__main__.A.m'

Versus:

>>> z.m.__name__
'm'

Change-Id: I2eb9f49f6d7578d5d4e3a40cbd695e6622f3f850
2015-08-10 14:42:41 -07:00
Joshua Harlow a0e4178a0d Prefix the 'safe_wrapper' function to be '_safe_wrapper'
This function should be hidden from public usage by
prefixing it with an underscore since this really is an
internal impl. detail and should be treated as such.

Change-Id: I3b1d6c73556d22de19923ca273a6dfc9c9b77e97
2015-08-09 00:03:11 -07:00
Jenkins 6129c158bd Merge "Allow LoopingCall to continue on exception in callee" 2015-07-28 08:56:02 +00:00
Jenkins 0040a59caa Merge "Denote what happens when no exceptions are passed in" 2015-07-27 12:21:37 +00:00
Joshua Harlow 5116f887c7 Denote what happens when no exceptions are passed in
When no exceptions are passed in and the exception
tuple is empty this appears to catch no exceptions so
document that this happens.

  >>> excps = ()
  >>> try:
  ...   raise IOError("I am broken")
  ... except excps:
  ...   print("captured")
  ...
  Traceback (most recent call last):
    File "<stdin>", line 2, in <module>
  IOError: I am broken

Change-Id: I141ffd53b8f864bb0502d2e022264ea3145213ff
2015-07-23 15:47:12 -07:00
Ilya Shakhat ff00781fdd Allow LoopingCall to continue on exception in callee
In some cases we don't want LoopingCall to iterrupt if there is
an uncaught exception in the callee. In case of exception LoopingCall
needs to wait similarly as if a call succeeded.

Co-Authored-By: Eugene Nikanorov <enikanorov@mirantis.com>

Related-Bug: #1458119

Change-Id: I58da03017b923cf5ec2223ecfc61c766726bd1de
2015-07-22 12:29:07 +03:00
Davanum Srinivas 390b9345bd save docstring, name etc using six.wraps
Per suggestion during review of this changeset:
Ic5d57fcf769a4af53cd1cf82a3ca93142dbdb03f

If we use six.wraps then it makes things better!

Depends-On: Ibd2410e0153053b5121155474e99752256c7e4b8
Change-Id: Icc14d61504b9db0d91aa9b177abdab57c2f7ee55
2015-07-11 15:36:32 +00:00
Davanum Srinivas 4d6dd3525e Copy RetryDecorator from oslo.vmware
RetryDecorator from oslo.vmware needs a better home. It allows
users to specify specific exceptions upon which the request can
be retried.

http://git.openstack.org/cgit/openstack/oslo.vmware/tree/oslo_vmware/api.py#n48


Depends-On: I0f07858e96ea3baf46f8a453e253b9ed29c7f7e2
Depends-On: I33bd2d9dff9cb7dc1a50177db7286b7317966784

Closes-Bug: #1465629
Change-Id: Ic5d57fcf769a4af53cd1cf82a3ca93142dbdb03f
2015-07-05 19:49:37 +00:00
Joshua Harlow cbb17bd160 Track created thread and disallow more than one start being active
Change-Id: I7120f238b5ea4ca050783caa9f54de6932c07716
2015-06-29 07:48:30 -07:00
Joshua Harlow 8cc9813e19 Have all the looping calls share a common run loop
This refactors the looping call subclasses to share
a common '_run_loop' function, this avoids duplicating that
code and taking advanage of the commonality of both of these
subclasses.

This also moves this code closer to not being dependent on
eventlet.

Change-Id: I61c0bbd6a7cda11f96374fd7c453ac5fa89ed613
2015-06-23 10:47:58 -07:00
Joshua Harlow bc2fb3d21a Use monotonic.monotonic and stopwatches instead of time.time
Monotonic time and oslo.utils stopwatches will not go backwards
and therefore will not cause periodicity + misc. problems where tasks
are ran again or at the wrong times in a system that is having its
clock altered (via ntpd or other).

Related-Bug: #1450438

Change-Id: I90881842185c607eb6c8ea5bb7326a37e1bc3742
2015-06-16 14:45:28 -07:00
Elena Ezhova 47d6f01abb Fix unit tests 2015-05-21 17:00:17 +03:00
Elena Ezhova dd2f334781 exported from oslo-incubator by graduate.sh 2015-05-21 16:51:40 +03:00