Skip to content

Commit

Permalink
CTX-6635: Improved timeout logic
Browse files Browse the repository at this point in the history
- If a request fails due to timeout it has a delay before retry
- Timeout now increases if retry was invoked due to timeout
- Standard, upload, and download requests have separate timeouts
- Timeouts now have a limit
- All downloads are done in chunks of 8 MB
- Download timeout is in-between chunks
  • Loading branch information
dule1322 committed Aug 20, 2024
1 parent 377d49a commit 44756f9
Show file tree
Hide file tree
Showing 7 changed files with 199 additions and 142 deletions.
7 changes: 1 addition & 6 deletions coretex/_task/run_logger/run_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,7 @@ def uploadTaskRunLogs(taskRunId: int, logs: List[Log]) -> bool:
"logs": [log.encode() for log in logs]
}

response = networkManager.post(
"model-queue/add-console-log",
params,
timeout = (5, 600) # connection timeout 5 seconds, log upload timeout 600 seconds
)

response = networkManager.post("model-queue/add-console-log", params)
return not response.hasFailed()
except RequestFailedError as ex:
logging.getLogger("coretexpylib").error(f">> Failed to upload console logs to Coretex. Reason: {ex}")
Expand Down
2 changes: 1 addition & 1 deletion coretex/entities/dataset/network_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def _chunkSampleImport(sampleType: Type[SampleType], sampleName: str, samplePath
"file_id": fileChunkUpload(samplePath)
}

response = networkManager.formData("session/import", parameters, timeout = (5, 300))
response = networkManager.formData("session/import", parameters)
if response.hasFailed():
raise NetworkRequestError(response, f"Failed to create sample from \"{samplePath}\"")

Expand Down
32 changes: 17 additions & 15 deletions coretex/entities/sample/network_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,32 @@ def _download(self, ignoreCache: bool = False) -> None:
if self.downloadPath.exists() and self.modifiedSinceLastDownload():
ignoreCache = True

if ignoreCache and self.downloadPath.exists():
self.downloadPath.unlink()
if self.path.exists():
shutil.rmtree(self.path)
if ignoreCache:
# Delete downloadPath file
self.downloadPath.unlink(missing_ok = True)

if self.zipPath.exists() and self.isEncrypted:
self.zipPath.unlink()

if not ignoreCache and self.downloadPath.exists():
# If the downloadPath exists at this point do not redownload
if self.downloadPath.exists():
return

params = {
"id": self.id
}

response = networkManager.streamDownload(
f"{self._endpoint()}/export",
self.downloadPath,
params
)

response = networkManager.download(f"{self._endpoint()}/export", self.downloadPath, params)
if response.hasFailed():
raise NetworkRequestError(response, f"Failed to download Sample \"{self.name}\"")

if not response.isHead():
if self.isEncrypted:
# Delete the zipPath file, if Sample is encrypted
# downloadPath != zipPath, otherwise they point to same file
self.zipPath.unlink(missing_ok = True)

if self.path.exists():
# Delete the unzipped folder
shutil.rmtree(self.path)

@override
def download(self, decrypt: bool = True, ignoreCache: bool = False) -> None:
"""
Expand Down Expand Up @@ -252,6 +254,6 @@ def _overwriteSample(self, samplePath: Path) -> None:
else:
files.append(FileData.createFromPath("file", encryptedPath))

response = networkManager.formData(f"{self._endpoint()}/upload", params, files, timeout = (5, 300))
response = networkManager.formData(f"{self._endpoint()}/upload", params, files)
if response.hasFailed():
raise NetworkRequestError(response, f"Failed to overwrite Sample \"{self.name}\"")
Loading

0 comments on commit 44756f9

Please sign in to comment.