本文整理汇总了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
示例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
示例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
示例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)
示例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
)
)
示例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())
示例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()
示例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()
示例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()
示例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
示例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
示例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
示例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()
示例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()
示例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()