iOS AWS S3上传如何重试失败或故障的任务?

时间:2015-08-13 17:07:40

标签: ios amazon-s3 aws-sdk amazon-cognito awss3transfermanager

我正在使用iOS AWS SDK的批量上传[AWSTask taskForCompletionOfAllTasks:tasks] tasks数组是AWSTask *task = [self.transferManager upload:uploadRequest];个对象的数组。上传完成后,我可以通过数组枚举来检查所有任务是否成功。但是,我似乎无法弄清楚如何重试失败或故障的任务。如果我将一系列失败的任务传递给taskForCompletionOfAllTasks,它对这些任务没有做任何事情?

iOS AWS docs它没有提及有关重试失败或出现故障的任何事情。是的,有AWSServiceConfiguration.maxRetryCount但是在超过计数后重试故障或失败的任务并没有解决问题。 iOS AWS Examples也没有显示与此相关的任何内容。

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

0 个答案:

没有答案