Skip to content

Commit 703b6ab

Browse files
Add custom timeout in multipart upload (#132)
* update workflow before publishing python package * fix dependency issue and bump version * point to website in project description * fix broken dependency * improve doc * add github token to download artifacts * ensure only read-access @wvangeit * yet another attempt at downloading artifacts * make sure to use repo that ran the trigger wf * another attempt at fixing * change owner * allow publishing to testpypi also when pr * minor change * revert minor (but breaking) change * minor fix * add debug messages * another debug message * hopefully the final version * final fix * minor fix * move master and tag to individual jobs * add debug messages * dev->post * add python script for determining semantic version * minor changes * minor changes * improve error handling and add version file to artifacts * check if release * minor fix * ensure to enter venv * also when tagging * source venv in publishin workflow * ensure only master * add script for testing 'pure' semver * adapt workflows to new python script * minor change * attempt to evaluate expressions correctly * several fixes to fix tests * ensure repo is checked out in publish workflow * several small fixes * cleanup * debug * minor cleanup * mionr changes * add debug message * minor change * minor change * yet another try * minor change * minor change * minor change * mionr change * minor changes * correct workflow run id * cosmetic change * avoid using gh * change to a single job for publishing * minor cleanup * swap loops in clean up jobs * correction * add timeouts
1 parent c3efcf0 commit 703b6ab

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

clients/python/client/osparc/_files_api.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from . import ApiClient, File
2222
from ._http_client import AsyncHttpClient
2323
from ._utils import (
24+
DEFAULT_TIMEOUT_SECONDS,
2425
PaginationGenerator,
2526
compute_sha256,
2627
dev_features_enabled,
@@ -70,16 +71,24 @@ def download_file(
7071
downloaded_file = dest_file
7172
return str(downloaded_file.resolve())
7273

73-
def upload_file(self, file: Union[str, Path]):
74-
return asyncio.run(self.upload_file_async(file=file))
74+
def upload_file(
75+
self, file: Union[str, Path], timeout_seconds: int = DEFAULT_TIMEOUT_SECONDS
76+
):
77+
return asyncio.run(
78+
self.upload_file_async(file=file, timeout_seconds=timeout_seconds)
79+
)
7580

76-
async def upload_file_async(self, file: Union[str, Path]) -> File:
81+
async def upload_file_async(
82+
self, file: Union[str, Path], timeout_seconds: int = DEFAULT_TIMEOUT_SECONDS
83+
) -> File:
7784
if isinstance(file, str):
7885
file = Path(file)
7986
if not file.is_file():
8087
raise RuntimeError(f"{file} is not a file")
8188
checksum: str = compute_sha256(file)
82-
for file_result in self._search_files(sha256_checksum=checksum):
89+
for file_result in self._search_files(
90+
sha256_checksum=checksum, timeout_seconds=timeout_seconds
91+
):
8392
if file_result.filename == file.name:
8493
# if a file has the same sha256 checksum
8594
# and name they are considered equal
@@ -90,7 +99,7 @@ async def upload_file_async(self, file: Union[str, Path]) -> File:
9099
sha256_checksum=checksum,
91100
)
92101
client_upload_schema: ClientFileUploadData = self._super.get_upload_links(
93-
client_file=client_file
102+
client_file=client_file, _request_timeout=timeout_seconds
94103
)
95104
chunk_size: int = client_upload_schema.upload_schema.chunk_size
96105
links: FileUploadData = client_upload_schema.upload_schema.links
@@ -105,7 +114,7 @@ async def upload_file_async(self, file: Union[str, Path]) -> File:
105114

106115
uploaded_parts: list[UploadedPart] = []
107116
print("- uploading chunks...")
108-
async with AsyncHttpClient() as session:
117+
async with AsyncHttpClient(timeout=timeout_seconds) as session:
109118
async for chunck, size in tqdm(
110119
file_chunk_generator(file, chunk_size), total=n_urls
111120
):
@@ -126,15 +135,16 @@ async def upload_file_async(self, file: Union[str, Path]) -> File:
126135
base_url=self.api_client.configuration.host,
127136
follow_redirects=True,
128137
auth=self._auth,
138+
timeout=timeout_seconds,
129139
) as session:
130140
print(
131141
"- completing upload (this might take a couple of minutes)..."
132142
)
133-
file: File = await self._complete_multipart_upload(
143+
server_file: File = await self._complete_multipart_upload(
134144
session, links.complete_upload, client_file, uploaded_parts
135145
)
136146
print("- file upload complete")
137-
return file
147+
return server_file
138148

139149
async def _complete_multipart_upload(
140150
self,
@@ -175,11 +185,16 @@ async def _upload_chunck(
175185
return UploadedPart(number=index, e_tag=etag)
176186

177187
def _search_files(
178-
self, file_id: Optional[str] = None, sha256_checksum: Optional[str] = None
188+
self,
189+
file_id: Optional[str] = None,
190+
sha256_checksum: Optional[str] = None,
191+
timeout_seconds: int = DEFAULT_TIMEOUT_SECONDS,
179192
) -> PaginationGenerator:
180193
def pagination_method():
181194
return super(FilesApi, self).search_files_page(
182-
file_id=file_id, sha256_checksum=sha256_checksum
195+
file_id=file_id,
196+
sha256_checksum=sha256_checksum,
197+
_request_timeout=timeout_seconds,
183198
)
184199

185200
return PaginationGenerator(

clients/python/client/osparc/_utils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
_MB = _KB * 1024 # in bytes
2424
_GB = _MB * 1024 # in bytes
2525

26+
DEFAULT_TIMEOUT_SECONDS: int = 30 * 60
27+
2628
Page = Union[PageJob, PageFile, PageSolver, PageStudy]
2729
T = TypeVar("T", Job, File, Solver, Study)
2830

0 commit comments

Comments
 (0)