简体   繁体   中英

iOS AWS S3 Upload How To Retry Failed or Faulted Tasks?

I'm utilizing the iOS AWS SDK's batch upload [AWSTask taskForCompletionOfAllTasks:tasks] The tasks array is an array of AWSTask *task = [self.transferManager upload:uploadRequest]; objects. Once the upload is complete I can enumerate through the array to check to see if all the tasks were successful or not. However, I can't seem to figure out how to retry a failed or faulted task. If I pass an array of failed tasks to taskForCompletionOfAllTasks it doesn't do anything with those tasks?

The iOS AWS docs it doesn't mention anything about retrying on failed or faulted task. Yes, there is the AWSServiceConfiguration.maxRetryCount but that doesn't solve the issue with retrying faulted or failed tasks after that count as been exceeded. Also the iOS AWS Examples don't show anything in regards to this either.

- (void)performS3UploadWithRequest:(NSArray *)tasks withRetryCount:(int)retryCount
{

    if (retryCount == 0) {
        alert = [[UIAlertView alloc] initWithTitle:@"Failed to Upload Content"
                                           message:@"It appears we are having issues uploading your card information."
                                          delegate:self cancelButtonTitle:nil
                                 otherButtonTitles:@"Retry Upload", @"Retry Later", @"Cancel Order", nil];
        [alert show];
    } else {
        [[AWSTask taskForCompletionOfAllTasks:tasks] continueWithExecutor:[AWSExecutor mainThreadExecutor] withBlock:^id(AWSTask *task) {
            NSMutableArray *faultedTasks = [NSMutableArray new];
            for (AWSTask *finishedTask in tasks) {
                if (finishedTask.cancelled || finishedTask.faulted) {
                    [faultedTasks addObject:finishedTask];
                }
            }

            if (faultedTasks.count > 0) {
                [self performS3UploadWithRequest:faultedTasks withRetryCount:retryCount-1];
            } else {
                [[NSNotificationCenter defaultCenter] postNotificationName:kWHNotificationUploadDone object:self userInfo:nil];
            }
            return nil;
        }];
    }
}

You need to recreate the task object and reinitiate the task again. eg calling - upload: again.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM