How to use the tenacity.TryAgain function in tenacity

To help you get started, we’ve selected a few tenacity examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gnocchixyz / gnocchi / gnocchi / cli / metricd.py View on Github external
try:
            for sack in self.incoming.iter_on_sacks_to_process():
                if sack in self._get_sacks_to_process():
                    LOG.debug(
                        "Got notification for sack %s, waking up processing",
                        sack)
                    self.sacks_with_measures_to_process.add(sack)
                    self.wakeup()
        except exceptions.NotImplementedError:
            LOG.info("Incoming driver does not support notification")
        except Exception as e:
            LOG.error(
                "Error while listening for new measures notification, "
                "retrying",
                exc_info=True)
            raise tenacity.TryAgain(e)
github gnocchixyz / gnocchi / gnocchi / cli / metricd.py View on Github external
super(MetricProcessor, self)._configure()

        # create fallback in case paritioning fails or assigned no tasks
        self.fallback_tasks = list(self.incoming.iter_sacks())
        try:
            self.partitioner = self.coord.join_partitioned_group(
                self.GROUP_ID, partitions=200)
            LOG.info('Joined coordination group: %s',
                     self.GROUP_ID.decode())
        except tooz.NotImplemented:
            LOG.warning('Coordinator does not support partitioning. Worker '
                        'will battle against other workers for jobs.')
        except tooz.ToozError as e:
            LOG.error('Unexpected error configuring coordinator for '
                      'partitioning. Retrying: %s', e)
            raise tenacity.TryAgain(e)

        if self.conf.metricd.greedy:
            filler = threading.Thread(target=self._fill_sacks_to_process)
            filler.daemon = True
            filler.start()
github Mergifyio / mergify-engine / mergify_engine / tasks / engine / v1.py View on Github external
p.set_and_post_error("Merge fail")
                self._cache_save_pull(p)
                raise tenacity.TryAgain

        elif p.mergify_state == MergifyState.ALMOST_READY:
            LOG.info("waiting for final statuses completion", pull_request=p)

        elif p.mergify_state == MergifyState.NEED_BRANCH_UPDATE:
            if branch_updater.update(p, self._subscription["token"]):
                # Wait for the synchronize event now
                LOG.info("branch updated", pull_request=p)
            else:  # pragma: no cover
                p.set_and_post_error("contributor branch is not updatable, "
                                     "manual update/rebase required.")
                self._cache_save_pull(p)
                raise tenacity.TryAgain
github Mergifyio / mergify-engine / mergify_engine / mergify_pull.py View on Github external
def _wait_for_sha_change(self, old_sha):
        if self.g_pull.state == "closed" or self.g_pull.head.sha != old_sha:
            return

        # Github is currently processing this PR, we wait the completion
        self.log.info("refreshing")

        # NOTE(sileht): Well github doesn't always update etag/last_modified
        # when mergeable_state change, so we get a fresh pull request instead
        # of using update()
        self.g_pull = self.g_pull.base.repo.get_pull(self.g_pull.number)
        if self.g_pull.state == "closed" or self.g_pull.head.sha != old_sha:
            return
        raise tenacity.TryAgain
github ansible / ansibullbot / ansibullbot / utils / shippable_api.py View on Github external
def _fetch(verb='get'):
            headers = {
                'Authorization': 'apiToken %s' % C.DEFAULT_SHIPPABLE_TOKEN
            }

            logging.info(u'%s %s' % (verb, url))
            http_method = getattr(requests, verb)
            resp = http_method(url, headers=headers, **kwargs)
            logging.info(u'shippable status code: %s' % resp.status_code)
            logging.info(u'shippable reason: %s' % resp.reason)

            if resp.status_code not in [200, 302, 400]:
                logging.error(u'RC: %s', resp.status_code)
                raise TryAgain

            return resp
github openstack / tooz / tooz / drivers / _retry.py View on Github external
import tenacity
from tenacity import stop
from tenacity import wait


_default_wait = wait.wait_exponential(max=1)


def retry(stop_max_delay=None, **kwargs):
    k = {"wait": _default_wait, "retry": lambda x: False}
    if stop_max_delay not in (True, False, None):
        k['stop'] = stop.stop_after_delay(stop_max_delay)
    return tenacity.retry(**k)


TryAgain = tenacity.TryAgain
github ansible / ansibullbot / ansibullbot / utils / shippable_api.py View on Github external
def _inner_fetch(verb='get'):
        headers = {
            'Authorization': 'apiToken %s' % C.DEFAULT_SHIPPABLE_TOKEN
        }

        logging.info(u'%s %s' % (verb, url))
        http_method = getattr(requests, verb)
        resp = http_method(url, headers=headers, **kwargs)
        logging.info(u'shippable status code: %s' % resp.status_code)
        logging.info(u'shippable reason: %s' % resp.reason)

        if resp.status_code not in [200, 302, 400]:
            logging.error(u'RC: %s' % resp.status_code)
            raise TryAgain

        return resp
github Mergifyio / mergify-engine / mergify_engine / gh_pr_fullifier.py View on Github external
return
    if not force and pull.mergeable_state not in UNUSABLE_STATES:
        return

    # Github is currently processing this PR, we wait the completion
    # TODO(sileht): We should be able to do better that retry 15x
    LOG.info("%s, refreshing...", pull.pretty())

    # FIXME(sileht): Well github doesn't always update etag/last_modified
    # when mergeable_state change...
    pull._headers.pop(Consts.RES_ETAG, None)
    pull._headers.pop(Consts.RES_LAST_MODIFIED, None)
    pull.update()
    if pull.merged or pull.mergeable_state not in UNUSABLE_STATES:
        return
    raise tenacity.TryAgain
github kragniz / python-etcd3 / etcd3 / locks.py View on Github external
success, _ = self.etcd_client.transaction(
                compare=[
                    self.etcd_client.transactions.create(self.key) == 0
                ],
                success=[
                    self.etcd_client.transactions.put(self.key, self.uuid,
                                                      lease=self.lease)
                ],
                failure=[
                    self.etcd_client.transactions.get(self.key)
                ]
            )
            if success is True:
                return True
            self.lease = None
            raise tenacity.TryAgain