execute() публичный Метод

Executes the retry process.
public execute ( callable $function, array $arguments = [] ) : mixed
$function callable
$arguments array [optional]
Результат mixed
 public static function tearDownFixtures()
 {
     $backoff = new ExponentialBackoff(8);
     foreach (self::$deletionQueue as $item) {
         $backoff->execute(function () use($item) {
             $item->delete();
         });
     }
 }
 public static function tearDownFixtures()
 {
     if (empty(self::$deletionQueue)) {
         return;
     }
     $backoff = new ExponentialBackoff(8);
     $transaction = self::$client->transaction();
     $backoff->execute(function () use($transaction) {
         $transaction->deleteBatch(self::$deletionQueue);
     });
 }
 public static function tearDownFixtures()
 {
     if (!self::$hasSetUp) {
         return;
     }
     self::$deletionQueue[] = self::$object;
     self::$deletionQueue[] = self::$bucket;
     $backoff = new ExponentialBackoff(8);
     foreach (self::$deletionQueue as $item) {
         $backoff->execute(function () use($item) {
             $item->delete();
         });
     }
 }
 public function testExportsTable()
 {
     $object = self::$bucket->object(uniqid(self::TESTING_PREFIX));
     self::$deletionQueue[] = $object;
     $job = self::$table->export($object);
     $backoff = new ExponentialBackoff(8);
     $backoff->execute(function () use($job) {
         $job->reload();
         if (!$job->isComplete()) {
             throw new \Exception();
         }
     });
     if (!$job->isComplete()) {
         $this->fail('Job failed to complete within the allotted time.');
     }
     $this->assertArrayNotHasKey('errorResult', $job->info()['status']);
 }
 private function assertPsrLoggerWrites($client, $level)
 {
     $logName = uniqid(self::TESTING_PREFIX);
     $psrLogger = $client->psrLogger($logName);
     $logger = $client->logger($logName);
     self::$deletionQueue[] = $logger;
     $data = $level;
     $httpRequest = ['requestMethod' => 'GET'];
     $psrLogger->{$level}($data, ['stackdriverOptions' => ['httpRequest' => $httpRequest]]);
     $backoff = new ExponentialBackoff(8);
     $entries = $backoff->execute(function () use($logger) {
         $entries = iterator_to_array($logger->entries());
         if (count($entries) === 0) {
             throw new \Exception();
         }
         return $entries;
     });
     $actualEntryInfo = $entries[0]->info();
     $this->assertEquals($data, $actualEntryInfo['jsonPayload']['message']);
     $this->assertEquals($httpRequest['requestMethod'], $actualEntryInfo['httpRequest']['requestMethod']);
 }
 /**
  * Fetches credentials.
  *
  * @return array
  */
 private function fetchCredentials()
 {
     $backoff = new ExponentialBackoff($this->retries, $this->getRetryFunction());
     try {
         return $backoff->execute([$this->getCredentialsFetcher(), 'fetchAuthToken'], [$this->authHttpHandler]);
     } catch (\Exception $ex) {
         throw $this->convertToGoogleException($ex);
     }
 }
 /**
  * Deliver the request.
  *
  * @param callable $request The request to execute.
  * @param array $args The arguments for the request.
  * @param array $options [optional] {
  *     Request options.
  *
  *     @type int $retries Number of retries for a failed request.
  *           **Defaults to** `3`.
  *     @type array $grpcOptions gRPC specific configuration options.
  * }
  * @return array
  */
 public function send(callable $request, array $args, array $options = [])
 {
     $retries = isset($options['retries']) ? $options['retries'] : $this->retries;
     $grpcOptions = isset($options['grpcOptions']) ? $options['grpcOptions'] : $this->grpcOptions;
     $backoff = new ExponentialBackoff($retries, function (\Exception $ex) {
         $statusCode = $ex->getCode();
         if (in_array($statusCode, $this->grpcRetryCodes)) {
             return true;
         }
         return false;
     });
     if (!isset($grpcOptions['retrySettings'])) {
         $grpcOptions['retrySettings'] = new RetrySettings(null, null);
     }
     $optionalArgs =& $args[count($args) - 1];
     $optionalArgs += $grpcOptions;
     try {
         return $this->handleResponse($backoff->execute($request, $args));
     } catch (\Exception $ex) {
         throw $this->convertToGoogleException($ex);
     }
 }
 public function testSuccessWithNoRetries()
 {
     $actualAttempts = 0;
     $backoff = new ExponentialBackoff();
     $backoff->setDelayFunction($this->delayFunction);
     $backoff->execute(function () use(&$actualAttempts) {
         $actualAttempts++;
         return;
     });
     $this->assertEquals(1, $actualAttempts);
 }
 public function testRunQueryAsJobWithPositionalParameters()
 {
     $job = self::$client->runQueryAsJob('SELECT 1 IN UNNEST(?) AS arr', ['parameters' => [[1, 2, 3]]]);
     $results = $job->queryResults();
     $backoff = new ExponentialBackoff(8);
     $backoff->execute(function () use($results) {
         $results->reload();
         if (!$results->isComplete()) {
             throw new \Exception();
         }
     });
     if (!$results->isComplete()) {
         $this->fail('Query did not complete within the allotted time.');
     }
     $actualRows = iterator_to_array($results->rows());
     $expectedRows = [['arr' => true]];
     $this->assertEquals($expectedRows, $actualRows);
 }
Пример #10
0
 /**
  * Deliver the request.
  *
  * @param RequestInterface $request Psr7 request.
  * @param array $options [optional] {
  *     Request options.
  *
  *     @type int $retries Number of retries for a failed request.
  *           **Defaults to** `3`.
  *     @type array $httpOptions HTTP client specific configuration options.
  * }
  * @return ResponseInterface
  */
 public function send(RequestInterface $request, array $options = [])
 {
     $retries = isset($options['retries']) ? $options['retries'] : $this->retries;
     $httpOptions = isset($options['httpOptions']) ? $options['httpOptions'] : $this->httpOptions;
     $backoff = new ExponentialBackoff($retries, $this->getRetryFunction());
     $signedRequest = $this->shouldSignRequest ? $this->signRequest($request) : $request;
     try {
         return $backoff->execute($this->httpHandler, [$signedRequest, $httpOptions]);
     } catch (\Exception $ex) {
         throw $this->convertToGoogleException($ex);
     }
 }