Skip to content

Commit

Permalink
🐛 Refactor storage setup functions to avoid errors (ITISFoundation#6686)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrei Neagu <[email protected]>
  • Loading branch information
GitHK and Andrei Neagu authored Nov 8, 2024
1 parent d904673 commit 927319c
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions services/storage/src/simcore_service_storage/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@


async def setup_s3_client(app) -> AsyncGenerator[None, None]:
with log_context(log, logging.DEBUG, msg=f"setup {__name__}.setup.cleanup_ctx"):
client = None

with log_context(log, logging.DEBUG, msg="setup.s3_client.cleanup_ctx"):
storage_settings: Settings = app[APP_CONFIG_KEY]
storage_s3_settings = storage_settings.STORAGE_S3
assert storage_s3_settings # nosec

client = None
async for attempt in AsyncRetrying(
wait=wait_fixed(RETRY_WAIT_SECS),
before_sleep=before_sleep_log(log, logging.WARNING),
Expand All @@ -45,17 +46,21 @@ async def setup_s3_client(app) -> AsyncGenerator[None, None]:
assert client # nosec
app[APP_S3_KEY] = client

yield
# tear-down
yield

with log_context(log, logging.DEBUG, msg="teardown.s3_client.cleanup_ctx"):
if client:
await client.close()


async def setup_s3_bucket(app: web.Application):
storage_s3_settings = app[APP_CONFIG_KEY].STORAGE_S3
client = get_s3_client(app)
await client.create_bucket(
bucket=storage_s3_settings.S3_BUCKET_NAME, region=storage_s3_settings.S3_REGION
)
with log_context(log, logging.DEBUG, msg="setup.s3_bucket.cleanup_ctx"):
storage_s3_settings = app[APP_CONFIG_KEY].STORAGE_S3
client = get_s3_client(app)
await client.create_bucket(
bucket=storage_s3_settings.S3_BUCKET_NAME,
region=storage_s3_settings.S3_REGION,
)
yield


Expand Down

0 comments on commit 927319c

Please sign in to comment.