Wait for real volume readiness during initial bucket bootstrap
This commit is contained in:
@@ -24,9 +24,19 @@ except ClientError as exc:
|
||||
if exc.response['Error']['Code'] not in ('NoSuchBucketPolicy','404'): raise
|
||||
else:
|
||||
raise RuntimeError('Unexpected bucket policy; inspect it before starting API')
|
||||
try:
|
||||
storage.client.head_object(Bucket=storage.bucket, Key=HEALTH_KEY)
|
||||
except ClientError as exc:
|
||||
if exc.response['Error']['Code'] not in ('404','NoSuchKey'): raise
|
||||
storage.client.put_object(Bucket=storage.bucket, Key=HEALTH_KEY, Body=HEALTH_BYTES)
|
||||
deadline=time.monotonic()+90
|
||||
while True:
|
||||
try:
|
||||
try:
|
||||
storage.client.head_object(Bucket=storage.bucket, Key=HEALTH_KEY)
|
||||
except ClientError as exc:
|
||||
if exc.response['Error']['Code'] not in ('404','NoSuchKey'): raise
|
||||
# Fixed, reserved key/content: retry after uncertain PUT is safe.
|
||||
storage.client.put_object(Bucket=storage.bucket, Key=HEALTH_KEY, Body=HEALTH_BYTES)
|
||||
storage.ready()
|
||||
break
|
||||
except (BotoCoreError,ClientError):
|
||||
if time.monotonic()>=deadline:
|
||||
raise RuntimeError('Storage volumes did not become ready within bootstrap deadline') from None
|
||||
time.sleep(1)
|
||||
print('Private bucket ready; bootstrap is repeatable')
|
||||
|
||||
Reference in New Issue
Block a user