Skip to content

Commit 463269f

Browse files
author
Nicolas Malaval
committed
Solve eventual consistency issue
1 parent 48e08c3 commit 463269f

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

resume.py

+18-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import re
55
import sys
6+
import time
67

78
import common
89

@@ -86,10 +87,23 @@
8687
for instance in response_fleet['Instances']:
8788

8889
# Retrieve additional instance details
89-
try:
90-
response_describe = client.describe_instances(InstanceIds=instance['InstanceIds'])
91-
except Exception as e:
92-
logger.error('Failed to describe instances %s: %s' %(', '.join(instance['InstanceIds']), e))
90+
nb_retry = 1
91+
max_retries = 3
92+
e_msg = None
93+
while True:
94+
try:
95+
response_describe = client.describe_instances(InstanceIds=instance['InstanceIds'])
96+
break
97+
except Exception as e:
98+
# Retry if an error is returned because of eventual consistency
99+
if nb_retry <= max_retries:
100+
nb_retry += 1
101+
time.sleep(nb_retry)
102+
else:
103+
e_msg = str(e)
104+
break
105+
if e_msg:
106+
logger.error('Failed to describe instances %s: %s' %(', '.join(instance['InstanceIds']), e_msg))
93107
continue
94108

95109
# For each instance that was successfully launched

0 commit comments

Comments
 (0)