mirror of
https://github.com/ansible-collections/community.crypto.git
synced 2026-03-27 05:43:22 +00:00
acme modules: also support 503 for retries (#513)
* Also support 503 for retries. * Forgot to adjust status code comparison. * Also support 408.
This commit is contained in:
2
changelogs/fragments/513-acme-503.yml
Normal file
2
changelogs/fragments/513-acme-503.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
minor_changes:
|
||||
- "acme* modules - also support the HTTP 503 Service Unavailable and 408 Request Timeout response status for automatic retries (https://github.com/ansible-collections/community.crypto/pull/513)."
|
||||
@@ -52,18 +52,22 @@ else:
|
||||
IPADDRESS_IMPORT_ERROR = None
|
||||
|
||||
|
||||
RETRY_STATUS_CODES = (408, 429, 503)
|
||||
|
||||
|
||||
def _decode_retry(module, response, info, retry_count):
|
||||
if info['status'] != 429:
|
||||
if info['status'] not in RETRY_STATUS_CODES:
|
||||
return False
|
||||
|
||||
if retry_count >= 5:
|
||||
raise ACMEProtocolException(module, msg='Giving up after 5 retries', info=info, response=response)
|
||||
|
||||
# 429 and 503 should have a Retry-After header (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After)
|
||||
try:
|
||||
retry_after = min(max(1, int(info.get('retry-after'))), 60)
|
||||
except (TypeError, ValueError) as dummy:
|
||||
retry_after = 10
|
||||
module.log('Retrieved a 429 Too Many Requests on %s, retrying in %s seconds' % (info['url'], retry_after))
|
||||
module.log('Retrieved a %d HTTP status on %s, retrying in %s seconds' % (info['status'], info['url'], retry_after))
|
||||
|
||||
time.sleep(retry_after)
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user