Skip to content

Commit

Permalink
add provider try catch, minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Herraj committed Feb 3, 2025
1 parent 1e6568b commit 3bdec80
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
6 changes: 4 additions & 2 deletions merino/providers/manifest/backends/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ async def fetch(self) -> tuple[GetManifestResultCode, ManifestData | None]:
...

async def fetch_via_async_gcs_client(self) -> ManifestData | None:
"""Use an async GCS client to fetch the manifest from storage and return it as a tuple.
"""Use an async GCS client to fetch the manifest from bucket.
Returns:
A tuple of (GetManifestResultCode, dict or None)
ManifestData or None
Raises:
RuntimeError: If the async storage client fails to initialize
"""
...
9 changes: 8 additions & 1 deletion merino/providers/manifest/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,11 @@ def get_manifest_data(self) -> ManifestData | None:

async def get_manifest_data_via_async_client(self) -> ManifestData | None:
"""Return manifest data"""
return await self.backend.fetch_via_async_gcs_client()
manifest_via_async = None

try:
manifest_via_async = await self.backend.fetch_via_async_gcs_client()
except Exception:
# We don't want our provider to blow up in case a RuntimeError is thrown by async_gcs_client module
return None
return manifest_via_async
7 changes: 2 additions & 5 deletions merino/utils/gcs/async_gcs_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ async def get_manifest_from_blob(
logger.error(f"Unexpected error when downloading blob: {ex}")
return manifest

await self.close_client()
# close the client connection
await self.storage.close()

logger.info("Succussfully downloaded manifest blob via async client")
return manifest

async def close_client(self) -> None:
"""Close the async client"""
await self.storage.close()

0 comments on commit 3bdec80

Please sign in to comment.