예제 #1
0
 def test_G_ValidFiniteShortRetry(self):
     # [ G] short_retry makes a finite amount of valid delays
     is_empty = True
     for i in phlsys_tryloop.make_default_short_retry():
         is_empty = False
         secs = i.total_seconds()
         self.assertGreaterEqual(secs, 0)
         self.assertLess(secs, 3600)  # one hour is definitely not short
     self.assertFalse(is_empty)
 def test_G_ValidFiniteShortRetry(self):
     # [ G] short_retry makes a finite amount of valid delays
     is_empty = True
     for i in phlsys_tryloop.make_default_short_retry():
         is_empty = False
         secs = i.total_seconds()
         self.assertGreaterEqual(secs, 0)
         self.assertLess(secs, 3600)  # one hour is definitely not short
     self.assertFalse(is_empty)
def tryloop(f, identifier, detail):
    """Return the result of the supplied operation 'f', retry on exception.

    Will retry operation 'f' after a short delay if it raises, gives up after
    a few attempts.

    :f: a callable that can be invoked like so 'f()'
    :identifier: a short string identifier for the calling line of code
    :detail: a string of the variables associated with the call, e.g. repo name
    :returns: the return value of operation 'f', if successful

    """
    def on_tryloop_exception(e, delay):
        abdt_logging.on_retry_exception(identifier, detail, e, delay)

    delays = phlsys_tryloop.make_default_short_retry()

    return phlsys_tryloop.try_loop_delay(
        f, delays, onException=on_tryloop_exception)
예제 #4
0
def tryloop(f, identifier, detail):
    """Return the result of the supplied operation 'f', retry on exception.

    Will retry operation 'f' after a short delay if it raises, gives up after
    a few attempts.

    :f: a callable that can be invoked like so 'f()'
    :identifier: a short string identifier for the calling line of code
    :detail: a string of the variables associated with the call, e.g. repo name
    :returns: the return value of operation 'f', if successful

    """
    def on_tryloop_exception(e, delay):
        abdt_logging.on_retry_exception(identifier, detail, e, delay)

    delays = phlsys_tryloop.make_default_short_retry()

    return phlsys_tryloop.try_loop_delay(
        f, delays, onException=on_tryloop_exception)