make log_exception optional for s3 file download - there are expected cases when the file is not there and the function returns None (#511)
This commit is contained in:
@@ -65,13 +65,14 @@ class AsyncAWSClient:
|
|||||||
LOG.exception("S3 upload failed.", uri=uri)
|
LOG.exception("S3 upload failed.", uri=uri)
|
||||||
|
|
||||||
@execute_with_async_client(client_type=AWSClientType.S3)
|
@execute_with_async_client(client_type=AWSClientType.S3)
|
||||||
async def download_file(self, uri: str, client: AioBaseClient = None) -> bytes | None:
|
async def download_file(self, uri: str, client: AioBaseClient = None, log_exception: bool = True) -> bytes | None:
|
||||||
try:
|
try:
|
||||||
parsed_uri = S3Uri(uri)
|
parsed_uri = S3Uri(uri)
|
||||||
response = await client.get_object(Bucket=parsed_uri.bucket, Key=parsed_uri.key)
|
response = await client.get_object(Bucket=parsed_uri.bucket, Key=parsed_uri.key)
|
||||||
return await response["Body"].read()
|
return await response["Body"].read()
|
||||||
except Exception:
|
except Exception:
|
||||||
LOG.exception("S3 download failed", uri=uri)
|
if log_exception:
|
||||||
|
LOG.exception("S3 download failed", uri=uri)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@execute_with_async_client(client_type=AWSClientType.S3)
|
@execute_with_async_client(client_type=AWSClientType.S3)
|
||||||
|
|||||||
Reference in New Issue
Block a user