Skip to content

Commit

Permalink
On Azure .exists blob timeout, log the exception and return False
Browse files Browse the repository at this point in the history
We have been experimenting some issues with Azure Blob storage. Our current
timeout is the django-storages default (20 secs). We want to reduce it to ~2s,
but without breaking the code and start returning 500. So, we log the error and
return False.
  • Loading branch information
humitos committed Apr 13, 2020
1 parent 5b605e4 commit e3e2bee
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions readthedocs/storage/azure_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

"""Django storage classes to use with Azure Blob storage service."""

import logging
from azure.common import AzureMissingResourceHttpError
from django.conf import settings
from django.contrib.staticfiles.storage import ManifestFilesMixin
Expand All @@ -13,6 +14,9 @@
from .mixins import OverrideHostnameMixin


log = logging.getLogger(__name__)


class AzureBuildMediaStorage(BuildMediaStorageMixin, OverrideHostnameMixin, AzureStorage):

"""An Azure Storage backend for build artifacts."""
Expand All @@ -30,6 +34,14 @@ def url(self, name, expire=None, http_method=None): # noqa
"""
return super().url(name, expire)

def exists(self, name, timeout=None):
"""Override to catch timeout exception and return False."""
try:
return super().exists(name)
except:
log.exception('Timeout calling Azure .exists. name=%s', name)
return False


class AzureBuildStorage(AzureStorage):

Expand Down

0 comments on commit e3e2bee

Please sign in to comment.