forked from mtusi2026/mtusi2026lab4
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
|
if exc.response['Error']['Code'] not in ('NoSuchBucketPolicy','404'): raise
|
||||||
else:
|
else:
|
||||||
raise RuntimeError('Unexpected bucket policy; inspect it before starting API')
|
raise RuntimeError('Unexpected bucket policy; inspect it before starting API')
|
||||||
try:
|
deadline=time.monotonic()+90
|
||||||
storage.client.head_object(Bucket=storage.bucket, Key=HEALTH_KEY)
|
while True:
|
||||||
except ClientError as exc:
|
try:
|
||||||
if exc.response['Error']['Code'] not in ('404','NoSuchKey'): raise
|
try:
|
||||||
storage.client.put_object(Bucket=storage.bucket, Key=HEALTH_KEY, Body=HEALTH_BYTES)
|
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')
|
print('Private bucket ready; bootstrap is repeatable')
|
||||||
|
|||||||
Reference in New Issue
Block a user