本文整理汇总了Python中redo.retry函数的典型用法代码示例。如果您正苦于以下问题:Python retry函数的具体用法?Python retry怎么用?Python retry使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了retry函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_chain
def add_chain(self):
from redo import retry
import requests
import pem
def get_chain():
r = requests.get(self.chain_url)
r.raise_for_status()
return r.text
chain = retry(get_chain)
req = {"chain": []}
chain = pem.parse(chain)
for i in range(len(chain)):
cert = crypto.load_certificate(crypto.FILETYPE_PEM, str(chain[i]))
der = crypto.dump_certificate(crypto.FILETYPE_ASN1, cert)
req["chain"].append(base64.b64encode(der))
def post_chain():
r = requests.post(self.log_url + '/ct/v1/add-chain', json=req)
r.raise_for_status()
return r.json()
resp = retry(post_chain)
sct = SignedCertificateTimestamp(resp)
self.write_to_file(self.sct_filename, sct.to_rfc6962())
示例2: updateWorkloadStateTable
def updateWorkloadStateTable(self,action):
self.currentTime = str(datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
if (action == Orchestrator.ACTION_START) and (self.scalingProfile is not None):
UpdateExpressionAttr='SET Profile= :profile, LastActionTime= :currentTime, LastActionType= :actionType'
ExpressionAttributeValuesAttr={
':profile': self.scalingProfile,
':currentTime': self.currentTime,
':actionType': action
}
else:
UpdateExpressionAttr='SET LastActionTime= :currentTime, LastActionType= :actionType'
ExpressionAttributeValuesAttr={
':currentTime': self.currentTime,
':actionType': action,
}
try:
retry(self.WorkloadStateTable.update_item, attempts=5, sleeptime=0,jitter=0, kwargs= {
"Key":{
'Workload': self.partitionTargetValue,
},
"UpdateExpression":UpdateExpressionAttr,
"ExpressionAttributeValues":ExpressionAttributeValuesAttr
})
except Exception as e:
msg = 'Orchestrator::updateWorkloadStateTable() Exception encountered during DDB update %s -->' % e
logger.error(msg + str(e))
示例3: refresh_antivirus
def refresh_antivirus(self):
self.info("Refreshing clamav db...")
try:
redo.retry(lambda: sh.freshclam("--stdout", "--verbose", _timeout=300, _err_to_out=True))
self.info("Done.")
except sh.ErrorReturnCode:
self.warning("Freshclam failed, skipping DB update")
示例4: testRetrySelectiveExceptionSucceed
def testRetrySelectiveExceptionSucceed(self):
retry(
_raiseCustomException,
attempts=2,
sleeptime=0,
jitter=0,
retry_exceptions=(NewError,),
)
示例5: slavealloc_disable
def slavealloc_disable(self, machine, loanid):
try:
url = furl(current_app.config.get("SLAVEAPI_URL", None))
url.path.add(machine).add("actions").add("disable")
loan_bug = Loans.query.get(loanid).bug_id
postdata = dict(reason="Being loaned on slaveloan bug %s" % loan_bug)
retry(requests.post, args=(str(url),), kwargs=dict(data=postdata)).json()
return machine
except Exception as exc: # pylint: disable=W0703
logger.exception(exc)
self.retry(exc=exc)
示例6: _scan_files
def _scan_files(self):
"""Scan the files we've collected. We do the download and scan concurrently to make
it easier to have a coherent log afterwards. Uses the venv python."""
self.info("Refreshing clamav db...")
redo.retry(lambda:
sh.freshclam("--stdout", "--verbose", _timeout=300, _err_to_out=True))
self.info("Done.")
external_tools_path = os.path.join(
os.path.abspath(os.path.dirname(os.path.dirname(mozharness.__file__))), 'external_tools')
self.run_command([self.query_python_path(), os.path.join(external_tools_path,'extract_and_run_command.py'),
'-j{}'.format(self.config['scan_parallelization']),
'clamscan', '--no-summary', '--', self.dest_dir])
示例7: wait_for_started
def wait_for_started(self):
# late imports because we need the jenkins virtualenv to be activated
# (this is done in the constructor)
import redo
import requests
session = requests.Session()
def wait_for_jenkins():
if not session.get('http://localhost:8080').status_code == 200:
raise Exception('Jenkins did not start successfully.')
redo.retry(wait_for_jenkins, sleeptime=0.5, jitter=0, sleepscale=1,
attempts=120)
示例8: update_runnableapi
def update_runnableapi():
"""
Use it to update runnablejobs.json file.
"""
url = "https://index.taskcluster.net/v1/task/gecko.v2.%s.latest.firefox.decision/"
latest_task = retry(requests.get, args=(url % "mozilla-inbound", ),
kwargs={'headers': {'accept-encoding': 'json'}, 'verify': True}).json()
task_id = latest_task['taskId']
# The format of expires is like 2017-07-04T22:13:23.248Z and we only want 2017-07-04 part
expires = latest_task['expires'].split('T')[0]
time_tuple = datetime.datetime.strptime(expires, "%Y-%m-%d").timetuple()
new_timestamp = time.mktime(time_tuple)
path = ROOT_DIR + '/runablejobs.json'
# we do nothing if the timestamp of runablejobs.json is equal with the latest task
# otherwise we download and update it
if os.path.isfile(path):
with open(path, 'r+') as data:
# read the timesstamp of this task from json file
oldtime = json.loads(data.read())['meta']['timetamp']
if oldtime == new_timestamp:
print "The runnable json file is latest already."
return
else:
print "It's going to update your runnable jobs data."
download_runnable_jobs(new_timestamp, task_id)
else:
print "It's going to help you download the runnable jobs file."
download_runnable_jobs(new_timestamp, task_id)
示例9: query_push_by_revision
def query_push_by_revision(repo_url, revision, full=False, return_revision_list=False):
"""
Return a dictionary with meta-data about a push including:
* changesets
* date
* user
repo_url - represents the URL to clone a rep
revision - the revision used to set the query range
full - query whole information of a push if it's True
return_revision_list - return a list of revisions if it's True
"""
url = "%s?changeset=%s&tipsonly=1" % (JSON_PUSHES % {"repo_url": repo_url}, revision)
if full:
url += "&full=1"
LOG.debug("About to fetch %s" % url)
req = retry(requests.get, args=(url,))
data = req.json()
assert len(data) == 1, "We should only have information about one push"
if not full:
LOG.debug("Push info: %s" % str(data))
push_id, push_info = data.popitem()
push = Push(push_id=push_id, push_info=push_info)
else:
LOG.debug("Requesting the info with full=1 can yield too much unnecessary output " "to debug anything properly")
if return_revision_list:
return push.changesets[0].node
return push
示例10: query_pushes_by_pushid_range
def query_pushes_by_pushid_range(repo_url, start_id, end_id, version=VERSION, return_revision_list=False):
"""
Return an ordered list of pushes (oldest first).
repo_url - represents the URL to clone a repo
start_id - from which pushid to start with (oldest)
end_id - from which pushid to end with (most recent)
version - version of json-pushes to use (see docs)
return_revision_list - return a list of revisions if it's True
"""
push_list = []
url = "%s?startID=%s&endID=%s&version=%s&tipsonly=1" % (
JSON_PUSHES % {"repo_url": repo_url},
start_id - 1, # off by one to compensate for pushlog as it skips start_id
end_id,
version,
)
LOG.debug("About to fetch %s" % url)
req = retry(requests.get, args=(url,))
pushes = req.json()["pushes"]
for push_id in sorted(pushes.keys()):
# Querying by push ID is preferred because date ordering is
# not guaranteed (due to system clock skew)
# We can interact with self-serve with the 12 char representation
push_list.append(Push(push_id=push_id, push_info=pushes[push_id]))
if return_revision_list:
return _pushes_to_list(push_list)
return push_list
示例11: worker
def worker(item):
source, destination = item
def copy_key():
source_key = bucket.get_key(source)
dest_key = bucket.get_key(destination)
# According to http://docs.aws.amazon.com/AmazonS3/latest/API/RESTCommonResponseHeaders.html
# S3 key MD5 is represented as ETag, except when objects are
# uploaded using multipart method. In this case objects's ETag
# is constructed using its MD5, minus symbol, and number of
# part. See http://stackoverflow.com/questions/12186993/what-is-the-algorithm-to-compute-the-amazon-s3-etag-for-a-file-larger-than-5gb#answer-19896823
source_md5 = source_key.etag.split("-")[0]
if dest_key:
dest_md5 = dest_key.etag.split("-")[0]
else:
dest_md5 = None
if not dest_key:
self.info("Copying {} to {}".format(source, destination))
bucket.copy_key(destination, self.config["bucket_name"],
source)
elif source_md5 == dest_md5:
self.warning(
"{} already exists with the same content ({}), skipping copy".format(
destination, dest_md5))
else:
self.fatal(
"{} already exists with the different content (src ETag: {}, dest ETag: {}), aborting".format(
destination, source_key.etag, dest_key.etag))
return retry(copy_key, sleeptime=5, max_sleeptime=60,
retry_exceptions=(S3CopyError, S3ResponseError))
示例12: order
def order(self, asset, amount, style, order_id=None):
log.debug('ordering {} {}'.format(amount, asset.symbol))
if amount == 0:
log.warn('skipping 0 amount orders')
return None
if self.simulate_orders:
return super(ExchangeBlotter, self).order(
asset, amount, style, order_id
)
else:
order = retry(
action=self.exchange_order,
attempts=self.attempts['order_attempts'],
sleeptime=self.attempts['retry_sleeptime'],
retry_exceptions=(ExchangeRequestError,),
cleanup=lambda: log.warn('Ordering again.'),
args=(asset, amount, style),
)
self.open_orders[order.asset].append(order)
self.orders[order.id] = order
self.new_orders.append(order)
return order.id
示例13: get_changed_files
def get_changed_files(repository, revision):
"""
Get the set of files changed in the push headed by the given revision.
Responses are cached, so multiple calls with the same arguments are OK.
"""
key = repository, revision
if key not in _cache:
url = '%s/json-automationrelevance/%s' % (repository.rstrip('/'), revision)
logger.debug("Querying version control for metadata: %s", url)
def get_automationrelevance():
response = requests.get(url, timeout=5)
return response.json()
contents = retry(get_automationrelevance, attempts=2, sleeptime=10)
logger.debug('{} commits influencing task scheduling:'
.format(len(contents['changesets'])))
changed_files = set()
for c in contents['changesets']:
logger.debug(" {cset} {desc}".format(
cset=c['node'][0:12],
desc=c['desc'].splitlines()[0].encode('ascii', 'ignore')))
changed_files |= set(c['files'])
_cache[key] = changed_files
return _cache[key]
示例14: _get_product_uptake
def _get_product_uptake(self, tuxedo_server_url, auth,
related_product, os):
from redo import retry
import requests
url = get_tuxedo_uptake_url(tuxedo_server_url, related_product, os)
self.info("Requesting {} from tuxedo".format(url))
def get_tuxedo_page():
r = requests.get(url, auth=auth,
verify=False, timeout=60)
r.raise_for_status()
return r.content
def calculateUptake(page):
doc = xml.dom.minidom.parseString(page)
uptake_values = []
for element in doc.getElementsByTagName('available'):
for node in element.childNodes:
if node.nodeType == xml.dom.minidom.Node.TEXT_NODE and \
node.data.isdigit():
uptake_values.append(int(node.data))
if not uptake_values:
uptake_values = [0]
return min(uptake_values)
page = retry(get_tuxedo_page)
uptake = calculateUptake(page)
self.info("Current uptake for {} is {}".format(related_product, uptake))
return uptake
示例15: download_runnable_jobs
def download_runnable_jobs(new_timestamp, task_id=None):
if task_id:
url = TREEHERDER_HOST.format('mozilla-inbound', task_id)
data = retry(requests.get, args=(url, ), kwargs={'headers': headers}).json()
if len(data['results']) > 0:
data['meta'].update({'timetamp': new_timestamp})
with open(ROOT_DIR + '/runnablejobs.json', 'w') as f:
json.dump(data, f)