AWSS3TransferUtility:如何在应用重启后重试失败的上传任务

AWSS3TransferUtility: How to retry failed upload task after app restart

我想在应用重启后重试之前失败的 S3 上传任务。在应用程序初始化时,我调用

    // register a transfer utility object asynchronously
    AWSS3TransferUtility.register(
        with: configuration!,
        transferUtilityConfiguration: tuConf,
        forKey: "..." // redacted
    ) { (error) in
         if let error = error {
             // handle registration error.
            Logging.logError("Error in registration: \(error)")
         } else {
            Logging.logDebug("AWS S3 TransferUtility registration success, now check for pending tasks")
            DispatchQueue.global().asyncAfter(deadline: .now() + 2.0) {
                finishPendingTasks()
            }
        }
    }

这里是完成待处理任务的函数

  static func finishPendingTasks() {
    let transferUtility = AWSS3TransferUtility.default()
    let uploadTasks = transferUtility.getUploadTasks().result

    Logging.logDebug("Finish pending AWS upload tasks")
    var progressBlock: AWSS3TransferUtilityProgressBlock?
    progressBlock = {(task, progress) in
        DispatchQueue.main.async(execute: {
            // Do something e.g. Update a progress bar.
            Logging.logDebug("upload in process \(progress)")
        })
    }

    var completionHandler: AWSS3TransferUtilityUploadCompletionHandlerBlock?
    completionHandler = { (task, error) -> Void in
        DispatchQueue.main.async(execute: {
            // Do something e.g. Alert a user for transfer completion.
            // On failed uploads, `error` contains the error object.
            Logging.logDebug("upload completed1 \(task.bucket)")
            Logging.logDebug("upload completed2 \(String(describing: task.response))")
            Logging.logDebug("upload completed3 \(task.key)")
            Logging.logDebug("upload error \(String(describing: error))")
        })
    }

    let taskCount = uploadTasks?.count ?? 0
    Logging.logDebug("Number of upload tasks: \(taskCount)")
    for task in uploadTasks! {
        if let awsTask = task as? AWSS3TransferUtilityUploadTask {
            Logging.logDebug("Resuming uploading task key \(awsTask.key), transfer ID: \(awsTask.transferID), status: \(awsTask.status.rawValue)")
            awsTask.setCompletionHandler(completionHandler!)
            awsTask.setProgressBlock(progressBlock!)
            awsTask.resume() // <------- HAS NO EFFECT!
        }
    }
}

状态原始值为 0

不确定 resume() 是否触发了重试。某处记录了程序吗?

没有看到完成 handler/progress 阻止踢。

在查看 this 时,AWS 似乎并没有真正跟踪与任务相关的数据,看起来必须手动维护和上传数据。

知道如何处理重试吗?

默认重试次数好像是0次,可以通过设置

更改
AWSS3TransferUtilityConfiguration().retryLimit = ...

resume() 不适用于这种情况。