Skip to content

Commit

Permalink
chore: Update the TODOs for the upcoming fine-grained retry feature
Browse files Browse the repository at this point in the history
  • Loading branch information
LouisCAD committed Mar 5, 2025
1 parent 1c70bf9 commit 4f760e9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ class TransferUploader(
* Returns the transfer UUID once the upload completes successfully.
*/
suspend fun uploadAllOrThrow(updateState: (UploadState.Ongoing) -> Unit): String {
//TODO: To count bytes,
//TODO[UL-retry]: To count bytes,
// consider using AtomicInteger + MutableStateFlow<Unit>, or MutableStateFlow.update { }
// while making sure we don't exceed the max when there are retries,
// and properly go back to start when we retry a chunk.
// Also, how is ktor dealing with that?
var uploadedBytes = 0L
uploadFiles(onUploadBytes = { bytesSent ->
uploadedBytes += bytesSent
Expand All @@ -82,8 +85,8 @@ class TransferUploader(
remoteContainer = destination.container,
remoteUploadHost = destination.uploadHost
)
return uploadManager.finalizeUploadSession(session) //TODO: Also retry that if needed, and make sure the backend supports it.
//TODO: Ensure the thumbnails directory is renamed, as done in UploadWorker
return uploadManager.finalizeUploadSession(session) //TODO[UL-retry]: Also retry that if needed, and make sure the backend supports it.
//TODO[Thumbnails]: Ensure the thumbnails directory is renamed, as done in UploadWorker
}

private fun newUploadState(uploadedBytes: Long): UploadState.Ongoing {
Expand All @@ -96,7 +99,7 @@ class TransferUploader(

private suspend fun uploadFiles(onUploadBytes: suspend (bytesSent: Long) -> Unit) {
pickedFiles.forEachIndexed { index, pickedFile ->
//TODO: Keep track of where we left off last time, and support retries.
//TODO[UL-retry]: Keep track of where we left off last time, and support retries.
start(
targetFileUri = pickedFile.uri,
fileUUID = destination.filesUuid[index],
Expand Down Expand Up @@ -155,7 +158,7 @@ class TransferUploader(
for (chunkIndex in 0..lastChunkIndex) {
requestSemaphore.acquire()
SentryLog.i(TAG, "start for chunkIndex:$chunkIndex")
// TODO: Skip already uploaded chunks
//TODO[UL-retry]: Skip already uploaded chunks

val isLastChunk = chunkIndex == lastChunkIndex
val dataByteArray = getReusableByteArray(byteArrayPool, inputStream, chunkSize, isLastChunk)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ class UploadForegroundService : ForegroundService(Companion, redeliverIntentIfKi
info = startRequest.info
)

//TODO: Once we support resuming the upload:
//TODO[UL-retry]: Once we support resuming the upload:
// 1. Remove this big `isInternetConnectedFlow` thing and move it to just the uploader part.
// 2. Remove the loop (repeatWhileActive) below.
// 3. In the uploader, use a function named `uploadAllRemainingWithRetries` or something.
Expand Down Expand Up @@ -262,7 +262,7 @@ class UploadForegroundService : ForegroundService(Companion, redeliverIntentIfKi
transferUrl = url
)
}
//TODO: On give up, schedule a worker to cancel the upload
//TODO[UL-cancel]: On give up, schedule a worker to cancel the upload
}
}

Expand Down

0 comments on commit 4f760e9

Please sign in to comment.