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


Python decorators.retry_on_exception方法代码示例

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


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

示例1: add_node

# 需要导入模块: from charmhelpers.core import decorators [as 别名]
# 或者: from charmhelpers.core.decorators import retry_on_exception [as 别名]
def add_node(self, host, executors, labels=()):
        """Add a slave node with the given host name."""
        self.wait()

        client = self._make_client()

        @retry_on_exception(3, 3, exc_type=RETRIABLE)
        def _add_node():
            if client.node_exists(host):
                hookenv.log("Node exists - not adding")
                return

            hookenv.log("Adding node '%s' to Jenkins master" % host)

            # See the "Launch slave agent headlessly" section of the Jenkins
            # wiki page about distributed builds:
            #
            # https://wiki.jenkins-ci.org/display/JENKINS/Distributed+builds
            launcher = jenkins.LAUNCHER_JNLP

            client.create_node(
                host, int(executors), host, labels=labels, launcher=launcher)

            if not client.node_exists(host):
                hookenv.log(
                    "Failed to create node '%s'" % host, level=ERROR)

        return _add_node() 
开发者ID:jenkinsci,项目名称:jenkins-charm,代码行数:30,代码来源:api.py

示例2: charm_check_func

# 需要导入模块: from charmhelpers.core import decorators [as 别名]
# 或者: from charmhelpers.core.decorators import retry_on_exception [as 别名]
def charm_check_func():
    """Custom function to assess the status of the current unit

    @returns (status, message) - tuple of strings if an issue
    """

    @retry_on_exception(num_retries=10,
                        base_delay=2,
                        exc_type=DesyncedException)
    def _cluster_in_sync():
        '''Helper func to wait for a while for resync to occur

        @raise DesynedException: raised if local unit is not in sync
                                 with its peers
        '''
        if not cluster_in_sync():
            raise DesyncedException()

    min_size = config('min-cluster-size')
    # Ensure that number of peers > cluster size configuration
    if not is_sufficient_peers():
        return ('blocked', 'Insufficient peers to bootstrap cluster')

    if min_size and int(min_size) > 1:
        # Once running, ensure that cluster is in sync
        # and has the required peers
        if not is_bootstrapped():
            return ('waiting', 'Unit waiting for cluster bootstrap')
        elif is_bootstrapped():
            try:
                _cluster_in_sync()
                return ('active', 'Unit is ready and clustered')
            except DesyncedException:
                return ('blocked', 'Unit is not in sync')
    else:
        return ('active', 'Unit is ready') 
开发者ID:openstack,项目名称:charm-percona-cluster,代码行数:38,代码来源:percona_utils.py

示例3: ensure_api_responding

# 需要导入模块: from charmhelpers.core import decorators [as 别名]
# 或者: from charmhelpers.core.decorators import retry_on_exception [as 别名]
def ensure_api_responding(cls):
        """Check that the api service is responding.

        The retry_on_exception decorator will cause this method to be called
        until it succeeds or retry limit is exceeded"""
        hookenv.log('Checking API service is responding',
                    level=hookenv.WARNING)
        check_cmd = ['reactive/designate_utils.py', 'server-list']
        subprocess.check_call(check_cmd) 
开发者ID:openstack,项目名称:charm-designate,代码行数:11,代码来源:designate.py

示例4: get_keystone_manager

# 需要导入模块: from charmhelpers.core import decorators [as 别名]
# 或者: from charmhelpers.core.decorators import retry_on_exception [as 别名]
def get_keystone_manager(endpoint, token, api_version=None):
    """Return a keystonemanager for the correct API version

    If api_version has not been set then create a manager based on the endpoint
    Use this manager to query the catalogue and determine which api version
    should actually be being used. Return the correct client based on that.
    Function is wrapped in a retry_on_exception to catch the case where the
    keystone service is still initialising and not responding to requests yet.
    XXX I think the keystone client should be able to do version
        detection automatically so the code below could be greatly
        simplified

    @param endpoint: the keystone endpoint to point client at
    @param token: the keystone admin_token
    @param api_version: version of the keystone api the client should use
    @returns keystonemanager class used for interrogating keystone
    """
    if api_version:
        return _get_keystone_manager_class(endpoint, token, api_version)
    else:
        if 'v2.0' in endpoint.split('/'):
            manager = _get_keystone_manager_class(endpoint, token, 2)
        else:
            manager = _get_keystone_manager_class(endpoint, token, 3)
        if endpoint.endswith('/'):
            base_ep = endpoint.rsplit('/', 2)[0]
        else:
            base_ep = endpoint.rsplit('/', 1)[0]
        svc_id = None
        for svc in manager.api.services.list():
            if svc.type == 'identity':
                svc_id = svc.id
        version = None
        for ep in manager.api.endpoints.list():
            if ep.service_id == svc_id and hasattr(ep, 'adminurl'):
                version = ep.adminurl.split('/')[-1]
        if version and version == 'v2.0':
            new_ep = base_ep + "/" + 'v2.0'
            return _get_keystone_manager_class(new_ep, token, 2)
        elif version and version == 'v3':
            new_ep = base_ep + "/" + 'v3'
            return _get_keystone_manager_class(new_ep, token, 3)
        else:
            return manager 
开发者ID:openstack,项目名称:charm-keystone,代码行数:46,代码来源:manager.py


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