-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upload parallelism and retries #46
Conversation
completion: { result in | ||
switch result { | ||
case let .success(airtableTree): | ||
self?.logger.log(.upload, "Successfully uploaded tree.") | ||
self?.database.save([airtableTree], sentFromThisDevice: true) | ||
self?.database.remove(tree: tree) { | ||
self?.currentUploads[tree.phImageId] = nil; | ||
if (self != nil && self!.currentUploads.count == 0) { | ||
self?.presentUploadButton(isUploading: false) | ||
} | ||
self?.presentTreesFromDatabase() | ||
self?.uploadLocalTreesRecursively() | ||
} | ||
case let .failure(error): | ||
self?.failedUploadCount[tree.phImageId] = (self?.failedUploadCount[tree.phImageId] ?? 0) + 1 | ||
self?.currentUploads[tree.phImageId] = nil; | ||
self?.update(uploadProgress: 0.0, for: tree) | ||
self?.logger.log(.upload, "Error when uploading a local tree: \(error)") | ||
self?.uploadLocalTreesRecursively() | ||
if (self != nil && self!.currentUploads.count == 0) { | ||
self?.presentUploadButton(isUploading: false) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uploadLocalTreesRecursively
is getting a little long. The completion
callback seems like a good candidate for extraction. It seems to only use self
and tree
.
let sortedTrees = trees.sorted(by: \.createDate, order: .descending) | ||
while (self != nil && self!.currentUploads.count < self!.maxConcurrentUploads && self!.currentUploads.count < trees.count) { | ||
|
||
guard let tree = sortedTrees.first(where: { treeEntry in self?.currentUploads[treeEntry.phImageId] == nil && (self?.failedUploadCount[treeEntry.phImageId] ?? 0) < self!.maxUploadAttempts}) else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌🏼
Thanks for this folks, we used it as inspiration for #47 🙌🏻 |
This PR is an attempt at making photo uploads parallel and adding a retry mechanism as well.
3 attempts are made for each image. Currently, if the registration on AirTable fails, it will also re-upload the entire image which is not ideal.
Relates to issues #35 and #37.