Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some 5xx error code handling for function #5014

Merged
merged 6 commits into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions catalog/dags/providers/provider_api_scripts/stocksnap.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import json
import logging

import backoff
from requests.exceptions import HTTPError

from common.licenses import get_license_info
from common.loader import provider_details as prov
from providers.provider_api_scripts.provider_data_ingester import ProviderDataIngester
Expand Down Expand Up @@ -157,6 +160,17 @@ def _get_title(item):
img_title = " ".join(tags)
return img_title.title()

# Add a backoff on every request
# for 5XX error codes.
# See: https://github.com/WordPress/openverse/issues/4878
@backoff.on_exception(
backoff.expo,
HTTPError,
# 30 minutes
max_time=60 * 30,
# Only retry for 5xx errors
giveup=lambda e: e.response.status_code not in {502, 503, 504},
)
def _get_filesize(self, image_url):
"""Get the size of the image in bytes."""
resp = self.delayed_requester.head(image_url)
Expand Down