Exemplo n.º 1
0
 def _func(*args, **kwargs):
     result = None
     try:
         if self._retry_count:
             LOG.debug("Invoking %(func_name)s; retry count is "
                       "%(retry_count)d.",
                       {'func_name': func_name,
                        'retry_count': self._retry_count})
         result = f(*args, **kwargs)
     except self._exceptions:
         with excutils.save_and_reraise_exception() as ctxt:
             LOG.warn(_LW("Exception which is in the suggested list of "
                          "exceptions occurred while invoking function:"
                          " %s."),
                      func_name,
                      exc_info=True)
             if (self._max_retry_count != -1 and
                     self._retry_count >= self._max_retry_count):
                 LOG.error(_LE("Cannot retry %(func_name)s upon "
                               "suggested exception "
                               "since retry count (%(retry_count)d) "
                               "reached max retry count "
                               "(%(max_retry_count)d)."),
                           {'retry_count': self._retry_count,
                            'max_retry_count': self._max_retry_count,
                            'func_name': func_name})
             else:
                 ctxt.reraise = False
                 self._retry_count += 1
                 self._sleep_time += self._inc_sleep_time
                 return self._sleep_time
     raise LoopingCallDone(result)
Exemplo n.º 2
0
    def _wait_child(self):
        try:
            # Don't block if no child processes have exited
            pid, status = os.waitpid(0, os.WNOHANG)
            if not pid:
                return None
        except OSError as exc:
            if exc.errno not in (errno.EINTR, errno.ECHILD):
                raise
            return None

        if os.WIFSIGNALED(status):
            sig = os.WTERMSIG(status)
            LOG.info(_LI('Child %(pid)d killed by signal %(sig)d'),
                     dict(pid=pid, sig=sig))
        else:
            code = os.WEXITSTATUS(status)
            LOG.info(_LI('Child %(pid)s exited with status %(code)d'),
                     dict(pid=pid, code=code))

        if pid not in self.children:
            LOG.warning(_LW('pid %d not in child list'), pid)
            return None

        wrap = self.children.pop(pid)
        wrap.children.remove(pid)
        return wrap
Exemplo n.º 3
0
        def _inner():
            if initial_delay:
                greenthread.sleep(initial_delay)

            try:
                while self._running:
                    start = _ts()
                    self.f(*self.args, **self.kw)
                    end = _ts()
                    if not self._running:
                        break
                    delay = end - start - interval
                    if delay > 0:
                        LOG.warning(_LW('task %(func_name)r run outlasted '
                                        'interval by %(delay).2f sec'),
                                    {'func_name': self.f, 'delay': delay})
                    greenthread.sleep(-delay if delay < 0 else 0)
            except LoopingCallDone as e:
                self.stop()
                done.send(e.retvalue)
            except Exception:
                LOG.exception(_LE('in fixed duration looping call'))
                done.send_exception(*sys.exc_info())
                return
            else:
                done.send(True)
Exemplo n.º 4
0
    def _wait_child(self):
        try:
            # Don't block if no child processes have exited
            pid, status = os.waitpid(0, os.WNOHANG)
            if not pid:
                return None
        except OSError as exc:
            if exc.errno not in (errno.EINTR, errno.ECHILD):
                raise
            return None

        if os.WIFSIGNALED(status):
            sig = os.WTERMSIG(status)
            LOG.info(_LI('Child %(pid)d killed by signal %(sig)d'),
                     dict(pid=pid, sig=sig))
        else:
            code = os.WEXITSTATUS(status)
            LOG.info(_LI('Child %(pid)s exited with status %(code)d'),
                     dict(pid=pid, code=code))

        if pid not in self.children:
            LOG.warning(_LW('pid %d not in child list'), pid)
            return None

        wrap = self.children.pop(pid)
        wrap.children.remove(pid)
        return wrap
Exemplo n.º 5
0
 def _idle_for(result, elapsed):
     delay = elapsed - interval
     if delay > 0:
         func_name = reflection.get_callable_name(self.f)
         LOG.warning(_LW('Function %(func_name)r run outlasted '
                         'interval by %(delay).2f sec'),
                     {'func_name': func_name, 'delay': delay})
     return -delay if delay < 0 else 0
Exemplo n.º 6
0
 def _idle_for(result, elapsed):
     delay = round(elapsed - interval, 2)
     if delay > 0:
         func_name = reflection.get_callable_name(self.f)
         LOG.warning(_LW('Function %(func_name)r run outlasted '
                         'interval by %(delay).2f sec'),
                     {'func_name': func_name, 'delay': delay})
     return -delay if delay < 0 else 0
Exemplo n.º 7
0
 def _idle_for(result, elapsed):
     delay = elapsed - interval
     if delay > 0:
         LOG.warning(
             _LW("Function %(func_name)r run outlasted " "interval by %(delay).2f sec"),
             {"func_name": self.f, "delay": delay},
         )
     return -delay if delay < 0 else 0
Exemplo n.º 8
0
 def _idle_for(result, elapsed):
     delay = elapsed - interval
     if delay > 0:
         LOG.warning(
             _LW('Function %(func_name)r run outlasted '
                 'interval by %(delay).2f sec'), {
                     'func_name': self.f,
                     'delay': delay
                 })
     return -delay if delay < 0 else 0
Exemplo n.º 9
0
 def _idle_for(result, elapsed):
     delay = round(elapsed - interval, 2)
     if delay > 0:
         func_name = reflection.get_callable_name(self.f)
         LOG.warning(
             _LW('Function %(func_name)r run outlasted '
                 'interval by %(delay).2f sec'), {
                     'func_name': func_name,
                     'delay': delay
                 })
     elapsed_time = time.time() - start_time
     if timeout > 0 and elapsed_time > timeout:
         raise LoopingCallTimeOut(
             _('Looping call timed out after %.02f seconds') %
             elapsed_time)
     return -delay if delay < 0 else 0
Exemplo n.º 10
0
 def _func(*args, **kwargs):
     result = None
     try:
         if self._retry_count:
             LOG.debug(
                 "Invoking %(func_name)s; retry count is "
                 "%(retry_count)d.", {
                     'func_name': func_name,
                     'retry_count': self._retry_count
                 })
         result = f(*args, **kwargs)
     except self._exceptions:
         with excutils.save_and_reraise_exception() as ctxt:
             LOG.warn(_LW("Exception which is in the suggested list of "
                          "exceptions occurred while invoking function:"
                          " %s."),
                      func_name,
                      exc_info=True)
             if (self._max_retry_count != -1
                     and self._retry_count >= self._max_retry_count):
                 LOG.error(
                     _LE("Cannot retry %(func_name)s upon "
                         "suggested exception "
                         "since retry count (%(retry_count)d) "
                         "reached max retry count "
                         "(%(max_retry_count)d)."), {
                             'retry_count': self._retry_count,
                             'max_retry_count': self._max_retry_count,
                             'func_name': func_name
                         })
             else:
                 ctxt.reraise = False
                 self._retry_count += 1
                 self._sleep_time += self._inc_sleep_time
                 return self._sleep_time
     raise LoopingCallDone(result)