Skip to content

Commit 927319c

Browse files
GitHKAndrei Neagu
andauthored
🐛 Refactor storage setup functions to avoid errors (#6686)
Co-authored-by: Andrei Neagu <[email protected]>
1 parent d904673 commit 927319c

File tree

1 file changed

+14
-9
lines changed
  • services/storage/src/simcore_service_storage

1 file changed

+14
-9
lines changed

services/storage/src/simcore_service_storage/s3.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@
2121

2222

2323
async def setup_s3_client(app) -> AsyncGenerator[None, None]:
24-
with log_context(log, logging.DEBUG, msg=f"setup {__name__}.setup.cleanup_ctx"):
24+
client = None
25+
26+
with log_context(log, logging.DEBUG, msg="setup.s3_client.cleanup_ctx"):
2527
storage_settings: Settings = app[APP_CONFIG_KEY]
2628
storage_s3_settings = storage_settings.STORAGE_S3
2729
assert storage_s3_settings # nosec
2830

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

48-
yield
49-
# tear-down
49+
yield
50+
51+
with log_context(log, logging.DEBUG, msg="teardown.s3_client.cleanup_ctx"):
52+
if client:
5053
await client.close()
5154

5255

5356
async def setup_s3_bucket(app: web.Application):
54-
storage_s3_settings = app[APP_CONFIG_KEY].STORAGE_S3
55-
client = get_s3_client(app)
56-
await client.create_bucket(
57-
bucket=storage_s3_settings.S3_BUCKET_NAME, region=storage_s3_settings.S3_REGION
58-
)
57+
with log_context(log, logging.DEBUG, msg="setup.s3_bucket.cleanup_ctx"):
58+
storage_s3_settings = app[APP_CONFIG_KEY].STORAGE_S3
59+
client = get_s3_client(app)
60+
await client.create_bucket(
61+
bucket=storage_s3_settings.S3_BUCKET_NAME,
62+
region=storage_s3_settings.S3_REGION,
63+
)
5964
yield
6065

6166

0 commit comments

Comments
 (0)