These are chat archives for aws/aws-sdk-php

1st
Mar 2016
Ian Carpenter
@Sazpaimon
Mar 01 2016 17:29
Am I crazy, or is the append/prepend logic in Middleware backwards
it looks like if $prepend is true, it actually appends
/cc @jeskew
Jonathan Eskew
@jeskew
Mar 01 2016 17:39
It depends on if you’re talking about handling requests or handling responses
Ian Carpenter
@Sazpaimon
Mar 01 2016 17:44
Should it matter? If I do "appendSign", it should add my handler after everything else in the sign step
for instance, I was trying to do something like this: http://pastebin.com/1d6Lnvvs to log any exception, and it seems the handler was added before the retry handler, despite doing "appendSign", so I was getting Dynamo throttle exceptions before the retry handler got them
doing prependSign instead resolved it, but that seemed counter-intuitive to me
Jonathan Eskew
@jeskew
Mar 01 2016 18:00
Middleware functions take a request and return a response, so if middleware A receives a request, acts on it, and passes it to middleware B, then middleware B will necessarily handle the response before passing it back to middleware A
The fact that middlewares are added to steps by unshifting onto an array is an implementation detail — they are applied to requests in the correct order
Jonathan Eskew
@jeskew
Mar 01 2016 18:07
But middlewares will be applied to responses in reverse order
Try out this gist:
You will see that middlewares A & B are applied in AB BA order
The script should output:
Starting Middleware A
Starting Middleware B
The main event!
Finishing Middleware B
Finishing Middleware A
Ian Carpenter
@Sazpaimon
Mar 01 2016 18:58
So then I should be using prependSign
or perhaps better, use after('retry' ...)
Jonathan Eskew
@jeskew
Mar 01 2016 19:01
I think after(‘retry’…) would cause the same behavior
prependSign will accomplish what you want
Ian Carpenter
@Sazpaimon
Mar 01 2016 19:02
alright, sounds good
Ian Carpenter
@Sazpaimon
Mar 01 2016 19:17
would this be a good way to workaround the limitation of not having wait time in the feature/report-retries branch?
    $client->getHandlerList()->prependSign(
      function (callable $handler) {
        $queryTime = microtime(true);
        return function (CommandInterface $command, RequestInterface $request = null) use ($handler, $queryTime) {
          return $handler($command, $request)->then(function (ResultInterface $result) use ($queryTime) {
            if (isset($result['@metadata']['retriesAttempted']) && $result['@metadata']['retriesAttempted'] > 0) {
              $waitTime = microtime(true) - $queryTime;
            }
            return $result;
          });
        };
      }
    );
it seems to be working okay
Jonathan Eskew
@jeskew
Mar 01 2016 20:01
If you’re just logging, you might want to pass in a simpler function with Middleware::tap
actually, that wouldn’t let you keep a timer, so that might not work for your use case
Ian Carpenter
@Sazpaimon
Mar 01 2016 20:12
right, i wanted to use tap or mapResult, but that wouldn't let me add in the timer
as long as I'm not doing anything that isn't kosher