Inheritance: implements Tolerance\Operation\Runner\OperationRunner
Example #1
0
 /**
  * Add fault tolerance to the request.
  *
  * @param string|array $request
  *
  * @return array
  */
 protected function sendWithTolerance($request)
 {
     $operation = new Callback(function () use($request) {
         return $request->send();
     });
     // Creates the strategy used to wait between failing calls
     $waitStrategy = new CountLimited(new ExponentialBackOff(new SleepWaiter(), $request->timeUntilNextTry), $request->triesUntilFailure);
     // Creates the runner
     $runner = new RetryOperationRunner(new CallbackOperationRunner(), $waitStrategy);
     return $runner->run($operation);
 }
 public function sendRequestUntil($method, $uri, $body, callable $assertion, $maxExecutionTime = 10)
 {
     $runner = new RetryOperationRunner(new CallbackOperationRunner(), new ExecutionTimeLimited(new SleepWaiter(), $maxExecutionTime));
     $restApiBrowser = $this;
     $runner->run(new Callback(function () use($restApiBrowser, $method, $uri, $body, $assertion) {
         $restApiBrowser->sendRequest($method, $uri, $body);
         return $assertion();
     }));
 }