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

AWSS3TransferUtility: How to retry failed upload task after app restart(AWSS3TransferUtility:如何在应用重启后重试失败的上传任务)

本文介绍了AWSS3TransferUtility:如何在应用重启后重试失败的上传任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在应用重启后重试之前失败的S3上载任务。在app init上,我调用
    // 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!
        }
    }
}

状态rawValue为0

不确定Resume()是否是触发重试的原因。是否有记录在案的程序?

未看到完成处理程序/进度块生效。

查看this时,AWS似乎并未真正跟踪与任务关联的数据,似乎必须手动维护和上载数据。

知道如何处理重试吗?

推荐答案

默认情况下,重试限制似乎为0。可以通过设置

来更改
AWSS3TransferUtilityConfiguration().retryLimit = ...

Resume()在这种情况下不适用。

这篇关于AWSS3TransferUtility:如何在应用重启后重试失败的上传任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:AWSS3TransferUtility:如何在应用重启后重试失败的上传任务

基础教程推荐