How to use the tenacity.wait_exponential 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 openstack-charmers / zaza / zaza / openstack / charm_tests / ceph / tests.py View on Github external
        @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1, max=60),
                        reraise=True, stop=tenacity.stop_after_attempt(12))
        def _target_get_object():
            return target_client.get_object(_container, 'testfile')
        _, target_content = _target_get_object()
github openstack / ceilometer / ceilometer / coordination.py View on Github external
            wait=tenacity.wait_exponential(
                multiplier=self.conf.coordination.retry_backoff,
                max=self.conf.coordination.max_retry_interval),
            retry=tenacity.retry_never)
        def _inner():
            try:
                self._coordinator.join_group_create(group_id)
            except tooz.coordination.MemberAlreadyExist:
                pass
            except tooz.coordination.ToozError:
                LOG.exception('Error joining partitioning group %s,'
                              ' re-trying', group_id)
                raise tenacity.TryAgain
            LOG.info('Joined partitioning group %s', group_id)
github DataDog / integrations-core / .azure-pipelines / scripts / sqlserver / windows / 40_install_sqlserver.py View on Github external
@retry(wait=wait_exponential(min=2, max=60), stop=stop_after_attempt(5))
def install_sqlserver():
    """
    Install with TCP/IP enabled, see: https://chocolatey.org/packages/sql-server-2017
    """
    print("Install sql-server-2017 ...")
    subprocess.run(["choco", "install", "sql-server-2017", "--no-progress", "--params", "'/TCPENABLED:1'"], check=True)
github openstack-charmers / zaza / zaza / openstack / utilities / openstack.py View on Github external
:param expected_status: status to expect resource to reach
    :type expected_status: str
    :param msg: text to identify purpose in logging
    :type msg: str
    :param wait_exponential_multiplier: Wait 2^x * wait_exponential_multiplier
                                        seconds between each retry
    :type wait_exponential_multiplier: int
    :param wait_iteration_max_time: Wait a max of wait_iteration_max_time
                                    between retries.
    :type wait_iteration_max_time: int
    :param stop_after_attempt: Stop after stop_after_attempt retires.
    :type stop_after_attempt: int
    :raises: AssertionError
    """
    retryer = tenacity.Retrying(
        wait=tenacity.wait_exponential(
            multiplier=wait_exponential_multiplier,
            max=wait_iteration_max_time),
        reraise=True,
        stop=tenacity.stop_after_attempt(stop_after_attempt))
    retryer(
        _resource_reaches_status,
        resource,
        resource_id,
        expected_status,
        msg)
github axbaretto / beam / sdks / python / container / license_scripts / pull_licenses_py.py View on Github external
    wait=wait_exponential(multiplier=2),
    stop=stop_after_attempt(5))
def pull_from_url(dep, configs):
  '''
  :param dep: name of a dependency
  :param configs: a dict from dep_urls_py.yaml
  :return: boolean

  It downloads files form urls to a temp directory first in order to avoid
  to deal with any temp files. It helps keep clean final directory.
  '''
  if dep in configs:
    config = configs[dep]
    dest_dir = '/'.join([LICENSE_DIR, dep])
    cur_temp_dir = tempfile.mkdtemp()

    try:
github gnocchixyz / gnocchi / gnocchi / utils.py View on Github external
except AttributeError:
        fname = f.__name__

    @six.wraps(f)
    def _return_none_on_failure(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except Exception as e:
            LOG.critical("Unexpected error while calling %s: %s",
                         fname, e, exc_info=True)

    return _return_none_on_failure


# Retry with exponential backoff for up to 1 minute
wait_exponential = tenacity.wait_exponential(multiplier=0.5, max=60)

retry_on_exception = tenacity.Retrying(wait=wait_exponential)


class _retry_on_exception_and_log(tenacity.retry_if_exception_type):
    def __init__(self, msg):
        super(_retry_on_exception_and_log, self).__init__()
        self.msg = msg

    def __call__(self, attempt):
        if attempt.failed:
            LOG.error(self.msg, exc_info=attempt.exception())
        return super(_retry_on_exception_and_log, self).__call__(attempt)


def retry_on_exception_and_log(msg):
github openstack / zun / zun / container / cri / driver.py View on Github external
def retry_if_result_is_false(result):
            return result is False

        def check_init_container_stopped():
            status = self._show_container(context, container).status
            if status == consts.STOPPED:
                return True
            elif status == consts.RUNNING:
                return False
            else:
                raise exception.ZunException(
                    _("Container has unexpected status: %s") % status)

        r = tenacity.Retrying(
            stop=tenacity.stop_after_delay(timeout),
            wait=tenacity.wait_exponential(),
            retry=tenacity.retry_if_result(retry_if_result_is_false))
        r.call(check_init_container_stopped)
github openstack / networking-ovn / networking_ovn / agent / metadata / ovsdb.py View on Github external
        wait=tenacity.wait_exponential(max=180),
        reraise=True)
    def _get_ovsdb_helper(self, connection_string):
        return idlutils.get_schema_helper(connection_string, self.SCHEMA)
github istresearch / traptor / traptor / traptor.py View on Github external
        wait=wait_exponential(multiplier=1, max=10),
        stop=stop_after_attempt(3),
        reraise=True,
        retry=retry_if_exception_type(KafkaUnavailableError),
        after=log_retry_kafka,
    )
    def _send_enriched_data_to_kafka(self, tweet, enriched_data):
        """"
        Send the enriched data to Kafka

        :param tweet: the original tweet
        :param enriched_data: the enriched data to send
        """
        theLogMsg = "Attempting to send tweet to kafka"
        self.logger.info(theLogMsg, extra=logExtra({
                'tweet_id': tweet.get('id_str', None)
        }))
github CloudVE / cloudbridge / cloudbridge / providers / gcp / helpers.py View on Github external
                wait=tenacity.wait_exponential(max=10),
                reraise=True)
def gcp_metadata_save_op(provider, callback):
    """
    Carries out a metadata save operation. In GCP, a fingerprint based
    locking mechanism is used to prevent lost updates. A new fingerprint
    is returned each time metadata is retrieved. Therefore, this method
    retrieves the metadata, invokes the provided callback with that
    metadata, and saves the metadata using the original fingerprint
    immediately afterwards, ensuring that update conflicts can be detected.
    """
    def _save_common_metadata(provider):
        # get the latest metadata (so we get the latest fingerprint)
        metadata = get_common_metadata(provider)
        # allow callback to do processing on it
        callback(metadata)
        # save the metadata