helpers.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:kuberdock-platform 作者: cloudlinux 项目源码 文件源码
def fabric_retry(f, cmd, retry_pause, max_retries, exc_message=None, upd=None,
                 *f_args, **f_kwargs):
    """
    Retries the given function call until it succeed

    :param f: a function to retry, e.g. local or run
    :param cmd: command to execute
    :param retry_pause: pause between retries (seconds)
    :param max_retries: max retries num.
    :param exc_message: exception message template
    :param upd: db record of current update script
    :return: result of the cmd's stdout
    """
    for _ in range(max_retries):
        out = f(cmd, *f_args, **f_kwargs)
        if out.succeeded:
            return out
        if upd:
            upd.print_log('Retrying: {cmd}'.format(cmd=cmd))
        time.sleep(retry_pause)
    if exc_message:
        raise UpgradeError(exc_message.format(out=out), code=out.return_code)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号