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