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

廉价感情. 提交于 2021-02-10 05:45:06

问题


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;
        }];
    }
}

回答1:


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



来源:https://stackoverflow.com/questions/31994456/ios-aws-s3-upload-how-to-retry-failed-or-faulted-tasks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!