当前位置: 首页>>代码示例>>Python>>正文


Python tenacity.wait_exponential方法代码示例

本文整理汇总了Python中tenacity.wait_exponential方法的典型用法代码示例。如果您正苦于以下问题:Python tenacity.wait_exponential方法的具体用法?Python tenacity.wait_exponential怎么用?Python tenacity.wait_exponential使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tenacity的用法示例。


在下文中一共展示了tenacity.wait_exponential方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _wait_for_init_container

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def _wait_for_init_container(self, context, container, timeout=3600):
        def retry_if_result_is_false(result):
            return result is False

        def check_init_container_stopped():
            status = self.show(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) 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:driver.py

示例2: _wait_for_init_container

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def _wait_for_init_container(self, context, container, timeout=3600):
        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) 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:driver.py

示例3: quota_retry

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def quota_retry(*args, **kwargs) -> Callable:
        """
        A decorator that provides a mechanism to repeat requests in response to exceeding a temporary quote
        limit.
        """
        def decorator(fun: Callable):
            default_kwargs = {
                'wait': tenacity.wait_exponential(multiplier=1, max=100),
                'retry': retry_if_temporary_quota(),
                'before': tenacity.before_log(log, logging.DEBUG),
                'after': tenacity.after_log(log, logging.DEBUG),
            }
            default_kwargs.update(**kwargs)
            return tenacity.retry(
                *args, **default_kwargs
            )(fun)
        return decorator 
开发者ID:apache,项目名称:airflow,代码行数:19,代码来源:base_google.py

示例4: operation_in_progress_retry

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def operation_in_progress_retry(*args, **kwargs) -> Callable:
        """
        A decorator that provides a mechanism to repeat requests in response to
        operation in progress (HTTP 409)
        limit.
        """
        def decorator(fun: Callable):
            default_kwargs = {
                'wait': tenacity.wait_exponential(multiplier=1, max=300),
                'retry': retry_if_operation_in_progress(),
                'before': tenacity.before_log(log, logging.DEBUG),
                'after': tenacity.after_log(log, logging.DEBUG),
            }
            default_kwargs.update(**kwargs)
            return tenacity.retry(
                *args, **default_kwargs
            )(fun)
        return decorator 
开发者ID:apache,项目名称:airflow,代码行数:20,代码来源:base_google.py

示例5: retry_api_call

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def retry_api_call(func, config, logger=None, *args, **kwargs):
    retry = tenacity.Retrying(
        retry=retry_if_exception(
            lambda e: getattr(e, "response", {}).get("Error", {}).get("Code", None)
            in config.exceptions
            if e
            else False
        ),
        stop=stop_after_attempt(config.attempt),
        wait=wait_exponential(
            multiplier=config.multiplier,
            max=config.max_delay,
            exp_base=config.exponential_base,
        ),
        after=after_log(logger, logger.level) if logger else None,
        reraise=True,
    )
    return retry(func, *args, **kwargs) 
开发者ID:laughingman7743,项目名称:PyAthena,代码行数:20,代码来源:util.py

示例6: clone_git_repo

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def clone_git_repo(self, repo_url, repo_dir, rev="origin/branches/default/tip"):
        logger.info(f"Cloning {repo_url}...")

        if not os.path.exists(repo_dir):
            tenacity.retry(
                wait=tenacity.wait_exponential(multiplier=1, min=16, max=64),
                stop=tenacity.stop_after_attempt(5),
            )(
                lambda: subprocess.run(
                    ["git", "clone", "--quiet", repo_url, repo_dir], check=True
                )
            )()

        tenacity.retry(
            wait=tenacity.wait_exponential(multiplier=1, min=16, max=64),
            stop=tenacity.stop_after_attempt(5),
        )(
            lambda: subprocess.run(
                ["git", "fetch"], cwd=repo_dir, capture_output=True, check=True,
            )
        )()

        subprocess.run(
            ["git", "checkout", rev], cwd=repo_dir, capture_output=True, check=True
        ) 
开发者ID:mozilla,项目名称:bugbug,代码行数:27,代码来源:commit_classifier.py

示例7: retry_on_exception_and_log

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def retry_on_exception_and_log(msg):
    return tenacity.Retrying(
        wait=wait_exponential, retry=_retry_on_exception_and_log(msg)).wraps 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:5,代码来源:utils.py

示例8: send_batch

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def send_batch(
    bq,
    table,
    template_suffix,
    batch,
    *args,
    retry_max_attempts=None,
    retry_max_wait=None,
    retry_multiplier=None,
    **kwargs
):
    if retry_max_attempts is None:
        retry_max_attempts = 10
    if retry_max_wait is None:
        retry_max_wait = 60
    if retry_multiplier is None:
        retry_multiplier = 0.5

    # We split up send_batch and actually_send_batch so that we can use tenacity to
    # handle retries for us, while still getting to use the Nurser.start_soon interface.
    # This also makes it easier to deal with the error handling aspects of sending a
    # batch, from the work of actually sending. The general rule here is that errors
    # shoudl not escape from this function.

    send = actually_send_batch.retry_with(
        wait=tenacity.wait_exponential(multiplier=retry_multiplier, max=retry_max_wait),
        stop=tenacity.stop_after_attempt(retry_max_attempts),
    )

    try:
        await send(bq, table, template_suffix, batch, *args, **kwargs)
    # We've tried to send this batch to BigQuery, however for one reason or another
    # we were unable to do so. We should log this error, but otherwise we're going
    # to just drop this on the floor because there's not much else we can do here
    # except buffer it forever (which is not a great idea).
    except trio.TooSlowError:
        logger.error("Timed out sending %d items; Dropping them.", len(batch))
    except Exception:
        logger.exception("Error sending %d items; Dropping them.", len(batch)) 
开发者ID:pypa,项目名称:linehaul,代码行数:41,代码来源:server.py

示例9: run_with_advanced_retry

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def run_with_advanced_retry(self, _retry_args, *args, **kwargs):
        """
        Runs Hook.run() with a Tenacity decorator attached to it. This is useful for
        connectors which might be disturbed by intermittent issues and should not
        instantly fail.

        :param _retry_args: Arguments which define the retry behaviour.
            See Tenacity documentation at https://github.com/jd/tenacity
        :type _retry_args: dict


        .. code-block:: python

            hook = HttpHook(http_conn_id='my_conn',method='GET')
            retry_args = dict(
                 wait=tenacity.wait_exponential(),
                 stop=tenacity.stop_after_attempt(10),
                 retry=requests.exceptions.ConnectionError
             )
             hook.run_with_advanced_retry(
                     endpoint='v1/test',
                     _retry_args=retry_args
                 )

        """
        self._retry_obj = tenacity.Retrying(
            **_retry_args
        )

        return self._retry_obj(self.run, *args, **kwargs) 
开发者ID:apache,项目名称:airflow,代码行数:32,代码来源:http.py

示例10: download_bugs

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def download_bugs(bug_ids, products=None, security=False):
    old_bug_count = 0
    new_bug_ids = set(int(bug_id) for bug_id in bug_ids)
    for bug in get_bugs(include_invalid=True):
        old_bug_count += 1
        if int(bug["id"]) in new_bug_ids:
            new_bug_ids.remove(bug["id"])

    print(f"Loaded {old_bug_count} bugs.")

    new_bug_ids = sorted(list(new_bug_ids))

    CHUNK_SIZE = 100

    chunks = (
        new_bug_ids[i : (i + CHUNK_SIZE)]
        for i in range(0, len(new_bug_ids), CHUNK_SIZE)
    )

    @tenacity.retry(
        stop=tenacity.stop_after_attempt(7),
        wait=tenacity.wait_exponential(multiplier=1, min=16, max=64),
    )
    def get_chunk(chunk):
        new_bugs = get(chunk)

        if not security:
            new_bugs = [bug for bug in new_bugs.values() if len(bug["groups"]) == 0]

        if products is not None:
            new_bugs = [bug for bug in new_bugs.values() if bug["product"] in products]

        return new_bugs

    with tqdm(total=len(new_bug_ids)) as progress_bar:
        for chunk in chunks:
            new_bugs = get_chunk(chunk)

            progress_bar.update(len(chunk))

            db.append(BUGS_DB, new_bugs) 
开发者ID:mozilla,项目名称:bugbug,代码行数:43,代码来源:bugzilla.py

示例11: clone_git_repo

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def clone_git_repo(self, repo_url, repo_dir):
        if not os.path.exists(repo_dir):
            tenacity.retry(
                wait=tenacity.wait_exponential(multiplier=1, min=16, max=64),
                stop=tenacity.stop_after_attempt(5),
            )(
                lambda: subprocess.run(
                    ["git", "clone", "--quiet", repo_url, repo_dir], check=True
                )
            )()

            logger.info(f"{repo_dir} cloned")

        logger.info(f"Fetching {repo_dir}")

        tenacity.retry(
            wait=tenacity.wait_exponential(multiplier=1, min=16, max=64),
            stop=tenacity.stop_after_attempt(5),
        )(
            lambda: subprocess.run(
                ["git", "fetch", "--quiet"],
                cwd=repo_dir,
                capture_output=True,
                check=True,
            )
        )()

        logger.info(f"{repo_dir} fetched") 
开发者ID:mozilla,项目名称:bugbug,代码行数:30,代码来源:regressor_finder.py

示例12: clone_git_repo

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def clone_git_repo(self):
        tenacity.retry(
            wait=tenacity.wait_exponential(multiplier=1, min=16, max=64),
            stop=tenacity.stop_after_attempt(5),
        )(
            lambda: subprocess.run(
                ["git", "clone", "--quiet", self.repo_url, self.git_repo_path],
                check=True,
            )
        )()

        try:
            tenacity.retry(
                wait=tenacity.wait_exponential(multiplier=1, min=16, max=64),
                stop=tenacity.stop_after_attempt(5),
            )(
                lambda: subprocess.run(
                    ["git", "pull", "--quiet", self.repo_url, "master"],
                    cwd=self.git_repo_path,
                    capture_output=True,
                    check=True,
                )
            )()
        except subprocess.CalledProcessError as e:
            # When the repo is empty.
            if b"Couldn't find remote ref master" in e.stdout:
                pass 
开发者ID:mozilla,项目名称:bugbug,代码行数:29,代码来源:microannotate_generator.py

示例13: validate

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def validate(self, max_retries=0):
        """Performs basic **connection** validation of a sqlalchemy engine."""

        def _retry_on_exception(exc):
            LOG.warning("Engine connection (validate) failed due to '%s'", exc)
            if isinstance(exc, sa_exc.OperationalError) and \
               _is_db_connection_error(six.text_type(exc.args[0])):
                # We may be able to fix this by retrying...
                return True
            if isinstance(exc, (sa_exc.TimeoutError,
                                sa_exc.ResourceClosedError,
                                sa_exc.DisconnectionError)):
                # We may be able to fix this by retrying...
                return True
            # Other failures we likely can't fix by retrying...
            return False

        @tenacity.retry(
            stop=tenacity.stop_after_attempt(max(0, int(max_retries))),
            wait=tenacity.wait_exponential(),
            reraise=True,
            retry=tenacity.retry_if_exception(_retry_on_exception)
        )
        def _try_connect(engine):
            # See if we can make a connection happen.
            #
            # NOTE(harlowja): note that even though we are connecting
            # once it does not mean that we will be able to connect in
            # the future, so this is more of a sanity test and is not
            # complete connection insurance.
            with contextlib.closing(engine.connect()):
                pass

        _try_connect(self._engine) 
开发者ID:openstack,项目名称:taskflow,代码行数:36,代码来源:impl_sqlalchemy.py

示例14: test_exponential

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def test_exponential(self):
        r = Retrying(wait=tenacity.wait_exponential())
        self.assertEqual(r.wait(1, 0), 1)
        self.assertEqual(r.wait(2, 0), 2)
        self.assertEqual(r.wait(3, 0), 4)
        self.assertEqual(r.wait(4, 0), 8)
        self.assertEqual(r.wait(5, 0), 16)
        self.assertEqual(r.wait(6, 0), 32)
        self.assertEqual(r.wait(7, 0), 64)
        self.assertEqual(r.wait(8, 0), 128) 
开发者ID:jd,项目名称:tenacity,代码行数:12,代码来源:test_tenacity.py

示例15: test_exponential_with_max_wait

# 需要导入模块: import tenacity [as 别名]
# 或者: from tenacity import wait_exponential [as 别名]
def test_exponential_with_max_wait(self):
        r = Retrying(wait=tenacity.wait_exponential(max=40))
        self.assertEqual(r.wait(1, 0), 1)
        self.assertEqual(r.wait(2, 0), 2)
        self.assertEqual(r.wait(3, 0), 4)
        self.assertEqual(r.wait(4, 0), 8)
        self.assertEqual(r.wait(5, 0), 16)
        self.assertEqual(r.wait(6, 0), 32)
        self.assertEqual(r.wait(7, 0), 40)
        self.assertEqual(r.wait(8, 0), 40)
        self.assertEqual(r.wait(50, 0), 40) 
开发者ID:jd,项目名称:tenacity,代码行数:13,代码来源:test_tenacity.py


注:本文中的tenacity.wait_exponential方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。