mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add in a retry loop for route53 requests
The route53 api doesn't allow multiple overlapping requests, so if it is still processing a previous request when the next comes in will return an error. Fixes #4085
This commit is contained in:
parent
7b9e877970
commit
bd10aad71f
1 changed files with 16 additions and 1 deletions
|
@ -120,6 +120,7 @@ EXAMPLES = '''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import boto
|
import boto
|
||||||
|
@ -129,6 +130,20 @@ except ImportError:
|
||||||
print "failed=True msg='boto required for this module'"
|
print "failed=True msg='boto required for this module'"
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def commit(changes):
|
||||||
|
"""Commit changes, but retry PriorRequestNotComplete errors."""
|
||||||
|
retry = 10
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
retry -= 1
|
||||||
|
return changes.commit()
|
||||||
|
except boto.route53.exception.DNSServerError, e:
|
||||||
|
code = e.body.split("<Code>")[1]
|
||||||
|
code = code.split("</Code>")[0]
|
||||||
|
if code != 'PriorRequestNotComplete' or retry < 0:
|
||||||
|
raise e
|
||||||
|
time.sleep(500)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
|
@ -240,7 +255,7 @@ def main():
|
||||||
change.add_value(v)
|
change.add_value(v)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
result = changes.commit()
|
result = commit(changes)
|
||||||
except boto.route53.exception.DNSServerError, e:
|
except boto.route53.exception.DNSServerError, e:
|
||||||
txt = e.body.split("<Message>")[1]
|
txt = e.body.split("<Message>")[1]
|
||||||
txt = txt.split("</Message>")[0]
|
txt = txt.split("</Message>")[0]
|
||||||
|
|
Loading…
Reference in a new issue