Skip to content

Commit

Permalink
Remove another wait time
Browse files Browse the repository at this point in the history
  • Loading branch information
mephenor committed Nov 28, 2024
1 parent d23b34b commit baa8e8d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
56 changes: 22 additions & 34 deletions src/ghga_connector/core/downloading/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,41 +132,29 @@ async def await_download_url(self) -> URLResponse:
2. the file size in bytes
"""
# get the download_url, wait if needed
wait_time = 0
while wait_time < self._max_wait_time:
try:
self._message_display.display(
f"Fetching file authorization for {self._file_id}"
)
url_and_headers = await get_file_authorization(
file_id=self._file_id,
work_package_accessor=self._work_package_accessor,
)
self._message_display.display(
f"Fetching download URL for {self._file_id}"
)
response = await get_download_url(
client=self._client, url_and_headers=url_and_headers
)
except exceptions.BadResponseCodeError as error:
self._message_display.failure(
"The request was invalid and returned a bad HTTP status code."
)
raise error
except exceptions.RequestFailedError as error:
self._message_display.failure("The request failed.")
raise error

if isinstance(response, RetryResponse):
retry_time = response.retry_after
wait_time += retry_time
self._message_display.display(
f"File staging, will try to download again in {retry_time} seconds"
)
else:
return response

raise exceptions.MaxWaitTimeExceededError(max_wait_time=self._max_wait_time)
try:
self._message_display.display(
f"Fetching file authorization for {self._file_id}"
)
url_and_headers = await get_file_authorization(
file_id=self._file_id,
work_package_accessor=self._work_package_accessor,
)
self._message_display.display(f"Fetching download URL for {self._file_id}")
response = await get_download_url(
client=self._client, url_and_headers=url_and_headers
)
except exceptions.BadResponseCodeError as error:
self._message_display.failure(
"The request was invalid and returned a bad HTTP status code."
)
raise error
except exceptions.RequestFailedError as error:
self._message_display.failure("The request failed.")
raise error

return response # type: ignore

async def get_download_url(self) -> URLResponse:
"""Fetch a presigned URL from which file data can be downloaded."""
Expand Down
4 changes: 2 additions & 2 deletions src/ghga_connector/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ async def download_files( # noqa: PLR0913

# check output file
output_file = output_dir / f"{file_name}.c4gh"
if output_file.exists():
raise exceptions.FileAlreadyExistsError(output_file=str(output_file))
# if output_file.exists():
# raise exceptions.FileAlreadyExistsError(output_file=str(output_file))

# with_suffix() might overwrite existing suffixes, do this instead
output_file_ongoing = output_file.parent / (output_file.name + ".part")
Expand Down

0 comments on commit baa8e8d

Please sign in to comment.