Skip to content

Commit

Permalink
Make read_timeout default to None, only use it if set
Browse files Browse the repository at this point in the history
  • Loading branch information
rzvoncek committed Oct 9, 2024
1 parent 0a7ee16 commit d02e684
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion medusa-example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ use_sudo_for_restore = True

;aws_cli_path = <Location of the aws cli binary if not in PATH>

; Read timeout in seconds for the storage provider.
; Read timeout in seconds for the storage provider. Not set by default.
;read_timeout = 60

[monitoring]
Expand Down
1 change: 0 additions & 1 deletion medusa/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def _build_default_config():
'region': 'default',
'backup_grace_period_in_days': 10,
'use_sudo_for_restore': 'True',
'read_timeout': 60
}

config['logging'] = {
Expand Down
2 changes: 1 addition & 1 deletion medusa/storage/azure_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, config):
logging.getLogger('azure.core.pipeline.policies.http_logging_policy').setLevel(logging.WARNING)
logging.getLogger('chardet.universaldetector').setLevel(logging.WARNING)

self.read_timeout = int(config.read_timeout)
self.read_timeout = int(config.read_timeout) if 'read_timeout' in dir(config) and config.read_timeout else None

super().__init__(config)

Expand Down
6 changes: 3 additions & 3 deletions medusa/storage/google_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def __init__(self, config):

logging.getLogger('gcloud.aio.storage.storage').setLevel(logging.WARNING)

self.read_timeout = int(config.read_timeout)
self.read_timeout = int(config.read_timeout) if 'read_timeout' in dir(config) and config.read_timeout else None

super().__init__(config)

Expand Down Expand Up @@ -158,7 +158,7 @@ async def _download_blob(self, src: str, dest: str):
stream = await self.gcs_storage.download_stream(
bucket=self.bucket_name,
object_name=object_key,
timeout=self.read_timeout if self.read_timeout is not None else -1,
timeout=self.read_timeout,
)
Path(file_path).parent.mkdir(parents=True, exist_ok=True)
with open(file_path, 'wb') as f:
Expand Down Expand Up @@ -243,7 +243,7 @@ async def _read_blob_as_bytes(self, blob: AbstractBlob) -> bytes:
bucket=self.bucket_name,
object_name=blob.name,
session=self.session,
timeout=self.read_timeout if self.read_timeout is not None else -1,
timeout=self.read_timeout,
)
return content

Expand Down
4 changes: 3 additions & 1 deletion medusa/storage/s3_base_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ def __init__(self, config):

self.executor = concurrent.futures.ThreadPoolExecutor(int(config.concurrent_transfers))

self.read_timeout = int(config.read_timeout) if 'read_timeout' in dir(config) and config.read_timeout else None

super().__init__(config)

def connect(self):
Expand All @@ -137,7 +139,7 @@ def connect(self):
signature_version='v4',
tcp_keepalive=True,
max_pool_connections=max_pool_size,
read_timeout=int(self.config.read_timeout),
read_timeout=self.read_timeout,
)
if self.credentials.access_key_id is not None:
self.s3_client = boto3.client(
Expand Down
1 change: 1 addition & 0 deletions tests/resources/config/medusa-s3_us_west_oregon.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ concurrent_transfers = 16
backup_grace_period_in_days = 0
max_backup_count = 1
region = us-west-2
read_timeout = 60

[monitoring]
monitoring_provider = local
1 change: 1 addition & 0 deletions tests/storage/abstract_storage_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class AttributeDict(dict):
__slots__ = ()
__getattr__ = dict.__getitem__
__setattr__ = dict.__setitem__
__dict__ = dict.__dict__


class TestAbstractStorage(AbstractStorage):
Expand Down

0 comments on commit d02e684

Please sign in to comment.