in skywalking/agent/__init__.py [0:0]
def report_with_backoff(reporter_name, init_wait):
"""
An exponential backoff for retrying reporters.
"""
def backoff_decorator(func):
@functools.wraps(func)
def backoff_wrapper(self, *args, **kwargs):
wait = base = init_wait
while not self._finished.is_set():
try:
flag = func(self, *args, **kwargs)
# for segment/log reporter, if the queue not empty(return True), we should keep reporter working
# for other cases(return false or None), reset to base wait time on success
wait = 0 if flag else base
except Exception: # noqa
wait = min(60, wait * 2 or 1) # double wait time with each consecutive error up to a maximum
logger.exception(f'Exception in {reporter_name} service in pid {os.getpid()}, '
f'retry in {wait} seconds')
self._finished.wait(wait)
logger.info('finished reporter thread')
return backoff_wrapper
return backoff_decorator