如何设置AWS Appsync请求超时限制|| AWSAppSync客户端未提供回调

时间:2018-10-31 12:29:19

标签: ios swift amazon-web-services aws-appsync aws-appsync-ios

我将AWS Appsync用于当前正在开发的App,并且遇到一个严重的问题,即每当我在Appsync客户端中触发查询时,当互联网连接速度慢时,请求就不会以回调结束。我通过互联网检查了有关此主题的信息来源有限,还有found this issue仍然开放。

这是我用来获取响应的代码

None

该代码可与Internet连接正常工作,并且我已经在顶部检查了是否没有Internet,但是当Internet连接速度慢或wifi连接到我用手机创建的热点时,该设备已禁用Internet数据不返回任何回调,它应该发出失败的警报,就像请求超时时我们进入其他api一样。 是否支持请求超时或我错过了什么?

  

注意:我在终端中收到了这些日志

def on_message(self, ws, msg):
    print(msg)

    self._result = None # default value

    if self._login_api_id < 0:
        result = json.loads(msg)
        self._login_api_id = result['id']
        self._send_msg([self._login_api_id, "history", []])
    elif self._history_api_id < 0:
        result = json.loads(msg)
        self._history_api_id = result['result']
        self._api_is_ready = True
    else:
        self._result = json.loads(msg)['result']
        self._ws.close()
        self.reset()

1 个答案:

答案 0 :(得分:2)

实际上,可能有两种方法可以解决此问题,

1)在配置PImage lion; PGraphics mask; void setup() { size(720, 380); lion = loadImage("lion.jpg"); mask = createGraphics(720, 380); mask.beginDraw(); mask.ellipse(0, 0, 150, 150); mask.fill(0, 0, 0); mask.endDraw(); mask.mask(lion); } void draw() { image(lion, 0, 0); } 时,提供自定义AWSAppSyncClientConfiguration并根据您的需要设置请求URLSessionConfiguration

timeout

并在初始化extension URLSessionConfiguration { /// A `URLSessionConfiguration` to have a request timeout of 1 minutes. static let customDelayed: URLSessionConfiguration = { let secondsInOneMinute = 60 let numberOfMinutesForTimeout = 1 let timoutInterval = TimeInterval(numberOfMinutesForTimeout * secondsInOneMinute) let configuration = URLSessionConfiguration.default configuration.timeoutIntervalForRequest = timoutInterval configuration.timeoutIntervalForResource = timoutInterval return configuration }() } 时传递此会话配置,即URLSessionConfiguration.customDelayed,因为它接受下面的构造函数中的AWSAppSyncClientConfiguration

URLSessionConfiguration

2)如果第一个不起作用,则您可以选择另一个选项来直接编辑/解锁Pod文件。有一个public convenience init(url: URL, serviceRegion: AWSRegionType, credentialsProvider: AWSCredentialsProvider, urlSessionConfiguration: URLSessionConfiguration = URLSessionConfiguration.default, databaseURL: URL? = nil, connectionStateChangeHandler: ConnectionStateChangeHandler? = nil, s3ObjectManager: AWSS3ObjectManager? = nil, presignedURLClient: AWSS3ObjectPresignedURLGenerator? = nil) throws { 类,您可以在其中更改重试请求的逻辑。如果您能够解决此问题,则可以派生原始存储库,克隆存储库,在存储库和Pod文件中进行更改,指向此Pod以使用您的存储库。之所以要这样做,是因为直接更改pod文件绝对是错误的,直到您真正陷入困境并想找到解决方案为止。

更新:此issue已通过AWSAppSyncRetryHandler修复