Use oslo_utils reflection to get function name
In order to get a better name, let's use oslo_utils reflection to get function name in RetryDecorator call. for example: from oslo_utils import reflection class Foo(object): def test_fun(self): pass foo = Foo() print(foo.test_fun.__name__) # "test_fun" print(reflection.get_callable_name(foo.test_fun)) # "__main__.Foo.test_fun" Change-Id: Ia7970b564e33ef7eafcd31fd907f4d53db1672f0
This commit is contained in:
parent
a89ac06029
commit
564e5ca578
@ -25,6 +25,7 @@ import logging
|
|||||||
|
|
||||||
from oslo_concurrency import lockutils
|
from oslo_concurrency import lockutils
|
||||||
from oslo_utils import excutils
|
from oslo_utils import excutils
|
||||||
|
from oslo_utils import reflection
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from oslo_vmware._i18n import _, _LE, _LI, _LW
|
from oslo_vmware._i18n import _, _LE, _LI, _LW
|
||||||
@ -82,9 +83,9 @@ class RetryDecorator(object):
|
|||||||
self._sleep_time = 0
|
self._sleep_time = 0
|
||||||
|
|
||||||
def __call__(self, f):
|
def __call__(self, f):
|
||||||
|
func_name = reflection.get_callable_name(f)
|
||||||
|
|
||||||
def _func(*args, **kwargs):
|
def _func(*args, **kwargs):
|
||||||
func_name = f.__name__
|
|
||||||
result = None
|
result = None
|
||||||
try:
|
try:
|
||||||
if self._retry_count:
|
if self._retry_count:
|
||||||
@ -118,7 +119,7 @@ class RetryDecorator(object):
|
|||||||
def func(*args, **kwargs):
|
def func(*args, **kwargs):
|
||||||
loop = loopingcall.DynamicLoopingCall(_func, *args, **kwargs)
|
loop = loopingcall.DynamicLoopingCall(_func, *args, **kwargs)
|
||||||
evt = loop.start(periodic_interval_max=self._max_sleep_time)
|
evt = loop.start(periodic_interval_max=self._max_sleep_time)
|
||||||
LOG.debug("Waiting for function %s to return.", f.__name__)
|
LOG.debug("Waiting for function %s to return.", func_name)
|
||||||
return evt.wait()
|
return evt.wait()
|
||||||
|
|
||||||
return func
|
return func
|
||||||
|
Loading…
x
Reference in New Issue
Block a user