當前位置: 首頁>>代碼示例>>Python>>正文


Python retrying.retry方法代碼示例

本文整理匯總了Python中retrying.retry方法的典型用法代碼示例。如果您正苦於以下問題:Python retrying.retry方法的具體用法?Python retrying.retry怎麽用?Python retrying.retry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在retrying的用法示例。


在下文中一共展示了retrying.retry方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _ensure_cluster_status_set

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def _ensure_cluster_status_set(t):
    m = t.send_raw(CMD_INFO)
    logging.debug('Ask `info` Rsp %s', m)
    cluster_enabled = PAT_CLUSTER_ENABLED.findall(m)
    if len(cluster_enabled) == 0 or int(cluster_enabled[0]) == 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is not cluster enabled' % (t.host, t.port))

    m = t.send_raw(CMD_CLUSTER_INFO)
    logging.debug('Ask `cluster info` Rsp %s', m)
    cluster_state = PAT_CLUSTER_STATE.findall(m)
    cluster_slot_assigned = PAT_CLUSTER_SLOT_ASSIGNED.findall(m)
    if cluster_state[0] != 'ok' and int(cluster_slot_assigned[0]) == 0:
        raise hiredis.ProtocolError(
            'Node %s:%d is not in a cluster' % (t.host, t.port))


# Redis instance responses to clients BEFORE changing its 'cluster_state'
#   just retry some times, it should become OK 
開發者ID:projecteru,項目名稱:redis-trib.py,代碼行數:21,代碼來源:command.py

示例2: retries

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def retries(f):
    """Decorator to retry a call three times if it raises Retry

    Note that this returns the actual value of the inner call on success
    or returns False if all the retries fail.
    """
    @functools.wraps(f)
    def wrapper(self, *a, **k):
        for retry in range(0, 4):
            try:
                sleep_time = random.uniform(0, retry * 2)
                time.sleep(sleep_time)
                return f(self, *a, **k)
            except Retry as e:
                LOG.debug(
                    'Unable to %(op)s because %(reason)s; retrying...',
                    {'op': e.operation, 'reason': e.reason})
        LOG.error('Failed scheduler client operation %s: out of retries',
                  f.__name__)
        return False
    return wrapper 
開發者ID:openstack,項目名稱:zun,代碼行數:23,代碼來源:report.py

示例3: retry_auth_check

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def retry_auth_check(exception, verbose):
  """Specific check for auth error codes.

  Return True if we should retry.

  False otherwise.
  Args:
    exception: An exception to test for transience.
    verbose: If true, output retry messages

  Returns:
    True if we should retry. False otherwise.
  """
  if isinstance(exception, googleapiclient.errors.HttpError):
    if exception.resp.status in HTTP_AUTH_ERROR_CODES:
      _print_retry_error(exception, verbose)
      return True

  return False 
開發者ID:DataBiosphere,項目名稱:dsub,代碼行數:21,代碼來源:google_base.py

示例4: test_endpoints_address

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def test_endpoints_address():
    foldered_name = sdk_utils.get_foldered_name(config.SERVICE_NAME)

    @retrying.retry(wait_fixed=1000, stop_max_delay=120 * 1000, retry_on_result=lambda res: not res)
    def wait():
        _, ret, _ = sdk_cmd.svc_cli(
            config.PACKAGE_NAME,
            foldered_name,
            "endpoints {}".format(config.DEFAULT_TASK_NAME),
            parse_json=True,
        )
        if len(ret["address"]) == config.DEFAULT_BROKER_COUNT:
            return ret
        return False

    endpoints = wait()
    # NOTE: do NOT closed-to-extension assert len(endpoints) == _something_
    assert len(endpoints["address"]) == config.DEFAULT_BROKER_COUNT
    assert len(endpoints["dns"]) == config.DEFAULT_BROKER_COUNT
    for i in range(len(endpoints["dns"])):
        assert (
            sdk_hosts.autoip_host(foldered_name, "kafka-{}-broker".format(i)) in endpoints["dns"][i]
        )
    assert endpoints["vip"] == sdk_hosts.vip_host(foldered_name, "broker", 9092) 
開發者ID:mesosphere,項目名稱:dcos-kafka-service,代碼行數:26,代碼來源:test_sanity.py

示例5: _remove_job_by_name

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def _remove_job_by_name(job_name: str) -> None:
    try:
        # Metronome doesn't understand 'True' -- only 'true' will do.
        sdk_cmd.service_request(
            "DELETE",
            "metronome",
            "/v1/jobs/{}".format(job_name),
            retry=False,
            params={"stopCurrentJobRuns": "true"},
        )
    except Exception as e:
        log.info(
            "Failed to remove any existing job named {} (this is likely as expected):\n{}".format(
                job_name, e
            )
        ) 
開發者ID:mesosphere,項目名稱:dcos-kafka-service,代碼行數:18,代碼來源:sdk_jobs.py

示例6: app_exists

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def app_exists(app_name: str, timeout: int = TIMEOUT_SECONDS) -> bool:
    # Custom config fetch: Allow 404 as signal that app doesn't exist. Retry on other errors.
    @retrying.retry(
        wait_fixed=1000,
        stop_max_delay=timeout * 1000,
        retry_on_exception=lambda e: isinstance(e, Exception),
    )
    def _app_exists() -> bool:
        response = sdk_cmd.cluster_request(
            "GET", _api_url("apps/{}".format(app_name)), raise_on_error=False
        )
        if response.status_code == 404:
            return False  # app doesn't exist
        response.raise_for_status()  # throw exception for (non-404) errors
        return True  # didn't get 404, and no other error code was returned, so app must exist.

    return bool(_app_exists()) 
開發者ID:mesosphere,項目名稱:dcos-kafka-service,代碼行數:19,代碼來源:sdk_marathon.py

示例7: check_scheduler_relaunched

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def check_scheduler_relaunched(
    service_name: str, old_scheduler_task_id: str, timeout_seconds: int = DEFAULT_TIMEOUT_SECONDS
) -> None:
    """
    This function checks for the relaunch of a task using the same matching as is
    used in sdk_task.get_task_id()
    """

    @retrying.retry(
        wait_fixed=1000, stop_max_delay=timeout_seconds * 1000, retry_on_result=lambda res: not res
    )
    def fn() -> bool:
        task_ids = set([t.id for t in get_service_tasks("marathon", task_prefix=service_name)])
        log.info("Found {} scheduler task ids {}".format(service_name, task_ids))
        return len(task_ids) > 0 and (old_scheduler_task_id not in task_ids or len(task_ids) > 1)

    fn() 
開發者ID:mesosphere,項目名稱:dcos-kafka-service,代碼行數:19,代碼來源:sdk_tasks.py

示例8: wait_for_active_framework

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def wait_for_active_framework(
    service_name: str, timeout_seconds: int = DEFAULT_TIMEOUT_SECONDS
) -> None:
    """
    Waits until a framework with name `framework_name` is found and is active
    """
    log.info("Waiting until [{}] is active".format(service_name))

    @retrying.retry(
        wait_fixed=1000, stop_max_delay=timeout_seconds * 1000, retry_on_result=lambda res: not res
    )
    def _wait_for_active_framework() -> bool:
        return (
            len(
                list(
                    filter(
                        lambda fwk: fwk["name"] == service_name and fwk["active"],
                        sdk_cmd.cluster_request("GET", "/mesos/frameworks").json()["frameworks"],
                    )
                )
            )
            > 0
        )

    _wait_for_active_framework() 
開發者ID:mesosphere,項目名稱:dcos-kafka-service,代碼行數:27,代碼來源:sdk_tasks.py

示例9: install_enterprise_cli

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def install_enterprise_cli(force: bool = False) -> None:
    """ Install the enterprise CLI if required """

    log.info("Installing DC/OS enterprise CLI")
    if not force:
        _, stdout, _ = sdk_cmd.run_cli("security --version", print_output=False)
        if stdout:
            log.info("DC/OS enterprise version %s CLI already installed", stdout.strip())
            return

    @retrying.retry(
        stop_max_attempt_number=3,
        wait_fixed=2000,
        retry_on_exception=lambda e: isinstance(e, Exception),
    )
    def _install_impl() -> None:
        sdk_cmd.run_cli("package install --yes --cli dcos-enterprise-cli", check=True)

    _install_impl() 
開發者ID:mesosphere,項目名稱:dcos-kafka-service,代碼行數:21,代碼來源:sdk_security.py

示例10: get_plan_once

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def get_plan_once(
    service_name: str, plan: str, multiservice_name: Optional[str] = None
) -> Dict[str, Any]:
    if multiservice_name is None:
        path = "/v1/plans/{}".format(plan)
    else:
        path = "/v1/service/{}/plans/{}".format(multiservice_name, plan)

    response = sdk_cmd.service_request("GET", service_name, path, retry=False, raise_on_error=False)
    if (
        response.status_code != 417
    ):  # Plan has errors: Avoid throwing an exception, return plan as-is.
        response.raise_for_status()

    result = response.json()
    assert isinstance(result, dict)
    return result 
開發者ID:mesosphere,項目名稱:dcos-kafka-service,代碼行數:19,代碼來源:sdk_plan.py

示例11: retry_throttled

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def retry_throttled(exception):
    """
    Determines if this exception is due to throttling
    :param exception:
    :return:
    """
    if isinstance(exception, botocore.exceptions.ClientError):
        if exception.response["Error"]["Code"] == "NoSuchEntity":
            return False

        # No need to retry deletion requests if there is a DeleteConflict error.
        # This error indicates that the certificate is still attached to an entity
        # and cannot be deleted.
        if exception.response["Error"]["Code"] == "DeleteConflict":
            return False

    metrics.send("iam_retry", "counter", 1, metric_tags={"exception": str(exception)})
    return True 
開發者ID:Netflix,項目名稱:lemur,代碼行數:20,代碼來源:iam.py

示例12: __enter__

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def __enter__(self):
        @retry(wait_exponential_multiplier=1000, wait_exponential_max=10000,
               stop_max_attempt_number=10,
               retry_on_exception=retry_on_exceptions)
        def setup():
            # Create a policy.
            policy = monitoring_v3.types.alert_pb2.AlertPolicy()
            json = open('test_alert_policy.json').read()
            google.protobuf.json_format.Parse(json, policy)
            policy.display_name = 'snippets-test-' + random_name(10)
            self.alert_policy = self.alert_policy_client.create_alert_policy(
                self.project_name, policy)
            # Create a notification channel.
            notification_channel = (
                monitoring_v3.types.notification_pb2.NotificationChannel())
            json = open('test_notification_channel.json').read()
            google.protobuf.json_format.Parse(json, notification_channel)
            notification_channel.display_name = (
                'snippets-test-' + random_name(10))
            self.notification_channel = (
                self.notification_channel_client.create_notification_channel(
                    self.project_name, notification_channel))
        setup()
        return self 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:26,代碼來源:snippets_test.py

示例13: __exit__

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def __exit__(self, type, value, traceback):
        # Delete the policy and channel we created.
        @retry(wait_exponential_multiplier=1000, wait_exponential_max=10000,
               stop_max_attempt_number=10,
               retry_on_exception=retry_on_exceptions)
        def teardown():
            try:
                self.alert_policy_client.delete_alert_policy(
                    self.alert_policy.name)
            except NotFound:
                print("Ignored NotFound when deleting a policy.")
            try:
                if self.notification_channel.name:
                    self.notification_channel_client\
                        .delete_notification_channel(
                            self.notification_channel.name)
            except NotFound:
                print("Ignored NotFound when deleting a channel.")
        teardown() 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:21,代碼來源:snippets_test.py

示例14: dest_dataset_id

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def dest_dataset_id():
    yield destination_dataset_id

    # Clean up
    @retry(
        wait_exponential_multiplier=1000,
        wait_exponential_max=10000,
        stop_max_attempt_number=10,
        retry_on_exception=retry_if_server_exception)
    def clean_up():
        try:
            datasets.delete_dataset(
                project_id, cloud_region, destination_dataset_id)
        except HttpError as err:
            # The API returns 403 when the dataset doesn't exist.
            if err.resp.status == 404 or err.resp.status == 403:
                print(
                    'Got exception {} while deleting dataset'.format(
                        err.resp.status))
            else:
                raise

    clean_up() 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:25,代碼來源:datasets_test.py

示例15: crud_dataset_id

# 需要導入模塊: import retrying [as 別名]
# 或者: from retrying import retry [as 別名]
def crud_dataset_id():
    yield dataset_id

    # Clean up
    @retry(
        wait_exponential_multiplier=1000,
        wait_exponential_max=10000,
        stop_max_attempt_number=10,
        retry_on_exception=retry_if_server_exception)
    def clean_up():
        try:
            datasets.delete_dataset(project_id, cloud_region, dataset_id)
        except HttpError as err:
            # The API returns 403 when the dataset doesn't exist.
            if err.resp.status == 404 or err.resp.status == 403:
                print(
                    'Got exception {} while deleting dataset'.format(
                        err.resp.status))
            else:
                raise

    clean_up() 
開發者ID:GoogleCloudPlatform,項目名稱:python-docs-samples,代碼行數:24,代碼來源:datasets_test.py


注:本文中的retrying.retry方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。