Retry failed attachment downloads

pull/250/head
nielsandriesse 5 years ago
parent 5e43d080c9
commit 1e3705978e

@ -378,19 +378,30 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
}); });
}; };
dispatch_async([OWSDispatch attachmentsQueue], ^{ __block NSUInteger retryCount = 0;
[self downloadFromLocation:attachmentPointer.downloadURL NSUInteger maxRetryCount = 4;
job:job __block void (^attempt)();
success:^(NSString *encryptedDataFilePath) { attempt = ^() {
[self decryptAttachmentPath:encryptedDataFilePath dispatch_async([OWSDispatch attachmentsQueue], ^{
attachmentPointer:attachmentPointer [self downloadFromLocation:attachmentPointer.downloadURL
success:markAndHandleSuccess job:job
failure:markAndHandleFailure]; success:^(NSString *encryptedDataFilePath) {
} [self decryptAttachmentPath:encryptedDataFilePath
failure:^(NSURLSessionTask *_Nullable task, NSError *error) { attachmentPointer:attachmentPointer
markAndHandleFailure(error); success:markAndHandleSuccess
}]; failure:markAndHandleFailure];
}); }
failure:^(NSURLSessionTask *task, NSError *error) {
if (retryCount == maxRetryCount) {
markAndHandleFailure(error);
} else {
retryCount += 1;
attempt();
}
}];
});
};
attempt();
} }
- (void)decryptAttachmentPath:(NSString *)encryptedDataFilePath - (void)decryptAttachmentPath:(NSString *)encryptedDataFilePath
@ -630,6 +641,7 @@ typedef void (^AttachmentDownloadFailure)(NSError *error);
} }
successHandler(tempFilePath); successHandler(tempFilePath);
}]; }];
[task resume]; [task resume];
} }

Loading…
Cancel
Save