Example #1
0
 def inner_func(*args, **kwargs):
     last_log_time = 0
     last_exc_message = None
     exc_count = 0
     while True:
         try:
             return infunc(*args, **kwargs)
         except Exception as exc:
             this_exc_message = six.u(str(exc))
             if this_exc_message == last_exc_message:
                 exc_count += 1
             else:
                 exc_count = 1
             # Do not log any more frequently than once a minute unless
             # the exception message changes
             cur_time = int(time.time())
             if (cur_time - last_log_time > 60
                     or this_exc_message != last_exc_message):
                 logging.exception(
                     _LE('Unexpected exception occurred %d time(s)... '
                         'retrying.') % exc_count)
                 last_log_time = cur_time
                 last_exc_message = this_exc_message
                 exc_count = 0
             # This should be a very rare event. In case it isn't, do
             # a sleep.
             time.sleep(1)
Example #2
0
 def wrapper(*args, **kwargs):
     last_exc_message = None
     same_failure_count = 0
     watch = timeutils.StopWatch(duration=same_log_delay)
     while True:
         try:
             return infunc(*args, **kwargs)
         except Exception as exc:
             this_exc_message = encodeutils.exception_to_unicode(exc)
             if this_exc_message == last_exc_message:
                 same_failure_count += 1
             else:
                 same_failure_count = 1
             if this_exc_message != last_exc_message or watch.expired():
                 # The watch has expired or the exception message
                 # changed, so time to log it again...
                 logging.exception(
                     _LE('Unexpected exception occurred %d time(s)... '
                         'retrying.') % same_failure_count)
                 if not watch.has_started():
                     watch.start()
                 else:
                     watch.restart()
                 same_failure_count = 0
                 last_exc_message = this_exc_message
             time.sleep(retry_delay)
Example #3
0
 def inner_func(*args, **kwargs):
     last_exc_message = None
     same_failure_count = 0
     watch = timeutils.StopWatch(duration=60)
     while True:
         try:
             return infunc(*args, **kwargs)
         except Exception as exc:
             this_exc_message = encodeutils.exception_to_unicode(exc)
             if this_exc_message == last_exc_message:
                 same_failure_count += 1
             else:
                 same_failure_count = 1
             if this_exc_message != last_exc_message or watch.expired():
                 # The watch has expired or the exception message
                 # changed, so time to log it again...
                 logging.exception(
                     _LE('Unexpected exception occurred %d time(s)... '
                         'retrying.') % same_failure_count)
                 if not watch.has_started():
                     watch.start()
                 else:
                     watch.restart()
                 same_failure_count = 0
                 last_exc_message = this_exc_message
             # This should be a very rare event. In case it isn't, do
             # a sleep.
             #
             # TODO(harlowja): why this is hard coded as one second
             # really should be fixed (since I'm not really sure why
             # one over some other value was chosen).
             time.sleep(1)
Example #4
0
 def inner_func(*args, **kwargs):
     last_log_time = 0
     last_exc_message = None
     exc_count = 0
     while True:
         try:
             return infunc(*args, **kwargs)
         except Exception as exc:
             this_exc_message = six.u(str(exc))
             if this_exc_message == last_exc_message:
                 exc_count += 1
             else:
                 exc_count = 1
             # Do not log any more frequently than once a minute unless
             # the exception message changes
             cur_time = int(time.time())
             if (cur_time - last_log_time > 60 or
                     this_exc_message != last_exc_message):
                 logging.exception(
                     _LE('Unexpected exception occurred %d time(s)... '
                         'retrying.') % exc_count)
                 last_log_time = cur_time
                 last_exc_message = this_exc_message
                 exc_count = 0
             # This should be a very rare event. In case it isn't, do
             # a sleep.
             time.sleep(1)
Example #5
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     if exc_type is not None:
         if self.reraise:
             self.logger.error(
                 _LE("Original exception being dropped: %s"),
                 traceback.format_exception(self.type_, self.value, self.tb),
             )
         return False
     if self.reraise:
         six.reraise(self.type_, self.value, self.tb)
Example #6
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     if exc_type is not None:
         if self.reraise:
             self.logger.error(
                 _LE('Original exception being dropped: %s'),
                 traceback.format_exception(self.type_, self.value,
                                            self.tb))
         return False
     if self.reraise:
         six.reraise(self.type_, self.value, self.tb)