Add support for network.file_upload_retries configuration option to control the UploadManager's file upload default retries

This commit is contained in:
allegroai 2022-12-13 15:35:19 +02:00
parent 5b38590756
commit 3da182426f
2 changed files with 10 additions and 5 deletions

View File

@ -42,6 +42,9 @@
} }
network { network {
# Number of retries before failing to upload file
file_upload_retries: 3
metrics { metrics {
# Number of threads allocated to uploading files (typically debug images) when transmitting metrics for # Number of threads allocated to uploading files (typically debug images) when transmitting metrics for
# a specific iteration # a specific iteration

View File

@ -9,13 +9,13 @@ from typing import List, Optional, Union
from zipfile import ZipFile from zipfile import ZipFile
from six.moves.urllib.parse import urlparse from six.moves.urllib.parse import urlparse
import requests
from pathlib2 import Path from pathlib2 import Path
from .cache import CacheManager from .cache import CacheManager
from .helper import StorageHelper from .helper import StorageHelper
from .util import encode_string_to_filename, safe_extract from .util import encode_string_to_filename, safe_extract
from ..debugging.log import LoggerRoot from ..debugging.log import LoggerRoot
from ..config import deferred_config
class StorageManager(object): class StorageManager(object):
@ -25,6 +25,8 @@ class StorageManager(object):
Cache is enabled by default for all downloaded remote urls/files Cache is enabled by default for all downloaded remote urls/files
""" """
_file_upload_retries = deferred_config("network.file_upload_retries", 3)
@classmethod @classmethod
def get_local_copy( def get_local_copy(
cls, remote_url, cache_context=None, extract_archive=True, name=None, force_download=False cls, remote_url, cache_context=None, extract_archive=True, name=None, force_download=False
@ -55,8 +57,8 @@ class StorageManager(object):
@classmethod @classmethod
def upload_file( def upload_file(
cls, local_file, remote_url, wait_for_upload=True, retries=3 cls, local_file, remote_url, wait_for_upload=True, retries=None
): # type: (str, str, bool, int) -> str ): # type: (str, str, bool, Optional[int]) -> str
""" """
Upload a local file to a remote location. remote url is the finale destination of the uploaded file. Upload a local file to a remote location. remote url is the finale destination of the uploaded file.
@ -71,14 +73,14 @@ class StorageManager(object):
:param str local_file: Full path of a local file to be uploaded :param str local_file: Full path of a local file to be uploaded
:param str remote_url: Full path or remote url to upload to (including file name) :param str remote_url: Full path or remote url to upload to (including file name)
:param bool wait_for_upload: If False, return immediately and upload in the background. Default True. :param bool wait_for_upload: If False, return immediately and upload in the background. Default True.
:param int retries: Number of retries before failing to upload file, default 3. :param int retries: Number of retries before failing to upload file.
:return: Newly uploaded remote URL. :return: Newly uploaded remote URL.
""" """
return CacheManager.get_cache_manager().upload_file( return CacheManager.get_cache_manager().upload_file(
local_file=local_file, local_file=local_file,
remote_url=remote_url, remote_url=remote_url,
wait_for_upload=wait_for_upload, wait_for_upload=wait_for_upload,
retries=retries, retries=retries if retries else cls._file_upload_retries,
) )
@classmethod @classmethod