blob: a7edb72b59628ab8f3f899800aaa0aecfd77d572 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
<?php
namespace Aws\Retry;
use Aws\Exception\AwsException;
use Aws\ResultInterface;
trait RetryHelperTrait
{
private function addRetryHeader($request, $retries, $delayBy)
{
return $request->withHeader('aws-sdk-retry', "{$retries}/{$delayBy}");
}
private function updateStats($retries, $delay, array &$stats)
{
if (!isset($stats['total_retry_delay'])) {
$stats['total_retry_delay'] = 0;
}
$stats['total_retry_delay'] += $delay;
$stats['retries_attempted'] = $retries;
}
private function updateHttpStats($value, array &$stats)
{
if (empty($stats['http'])) {
$stats['http'] = [];
}
if ($value instanceof AwsException) {
$resultStats = $value->getTransferInfo();
$stats['http'] []= $resultStats;
} elseif ($value instanceof ResultInterface) {
$resultStats = isset($value['@metadata']['transferStats']['http'][0])
? $value['@metadata']['transferStats']['http'][0]
: [];
$stats['http'] []= $resultStats;
}
}
private function bindStatsToReturn($return, array $stats)
{
if ($return instanceof ResultInterface) {
if (!isset($return['@metadata'])) {
$return['@metadata'] = [];
}
$return['@metadata']['transferStats'] = $stats;
} elseif ($return instanceof AwsException) {
$return->setTransferInfo($stats);
}
return $return;
}
}
|