Skip to content

Commit

Permalink
Retry all remaining GCS operations that may intermittently fail (#2185)
Browse files Browse the repository at this point in the history
In the same spirit of what was done in #2046 and #2049

Recently saw a transient 502 error in Production from the importer that
would have benefited from this, and decided to look more broadly for any
other situations where this could crop up in the future...
  • Loading branch information
andrewpollock authored May 9, 2024
1 parent 75a92ab commit af3d8c3
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docker/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from google.cloud import ndb
from google.cloud import pubsub_v1
from google.cloud import storage
from google.cloud.storage import retry
import pygit2.enums

import osv
Expand Down Expand Up @@ -87,7 +88,8 @@ def replace_importer_log(client: storage.Client, source_name: str,
bucket: storage.Bucket = client.bucket(bucket_name)
upload_string = '--- ' + datetime.datetime.utcnow().isoformat() + ' ---\n'
upload_string += '\n'.join(import_failure_logs)
bucket.blob(source_name).upload_from_string(upload_string)
bucket.blob(source_name).upload_from_string(
upload_string, retry=retry.DEFAULT_RETRY)


def log_run_duration(start: float):
Expand Down
3 changes: 2 additions & 1 deletion docker/worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from google.cloud import ndb
from google.cloud import pubsub_v1
from google.cloud import storage
from google.cloud.storage import retry

sys.path.append(os.path.dirname(os.path.realpath(__file__)))
import osv
Expand Down Expand Up @@ -378,7 +379,7 @@ def _source_update(self, message):
storage_client = storage.Client()
bucket = storage_client.bucket(source_repo.bucket)
try:
blob = bucket.blob(path).download_as_bytes()
blob = bucket.blob(path).download_as_bytes(retry=retry.DEFAULT_RETRY)
except google.cloud.exceptions.NotFound:
logging.exception('Bucket path %s does not exist.', path)
return
Expand Down

0 comments on commit af3d8c3

Please sign in to comment.