diff --git a/src/bootstrap_storage.py b/src/bootstrap_storage.py index 38cc43d..574a1d2 100644 --- a/src/bootstrap_storage.py +++ b/src/bootstrap_storage.py @@ -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')