diff --git a/src/Traits/RequestTrait.php b/src/Traits/RequestTrait.php index bca7eb0b..45608b4b 100644 --- a/src/Traits/RequestTrait.php +++ b/src/Traits/RequestTrait.php @@ -97,7 +97,8 @@ protected function doRequest($service, $method, array $data = []) json_decode($request->serializeToJsonString(), true) ); - $call = $this->client->$method($request, $this->meta); + $options = $this->buildGrpcOptions(); + $call = $this->client->$method($request, $this->meta, $options); if (method_exists($call, 'wait')) { list($response, $status) = $call->wait(); @@ -152,7 +153,8 @@ protected function doStreamRequest($service, $method, $data = []) $request = new $requestClass($data); - $call = $this->client->$method($request, $this->meta); + $options = $this->buildGrpcOptions(); + $call = $this->client->$method($request, $this->meta, $options); if (method_exists($call, 'responses')) { // $status = $call->getStatus(); @@ -238,7 +240,7 @@ protected function processResponse($service, $method, $response, $resultClass) $this->logger()->debug('YDB: Received API response [' . $resultClass . '].', json_decode($jsonResult, true)); $result = new $resultClass; - $result->mergeFromJsonString($jsonResult, true); + $result->mergeFromJsonString($jsonResult); } } @@ -323,6 +325,23 @@ protected function checkDiscovery(){ } } + /** + * Build gRPC call options including timeout if configured + * + * @return array + */ + protected function buildGrpcOptions() + { + $options = []; + + $timeout = $this->ydb->getGrpcTimeout(); + if ($timeout !== null) { + $options['timeout'] = $timeout; + } + + return $options; + } + public static $ydbExceptions = [ StatusCode::STATUS_CODE_UNSPECIFIED => \YdbPlatform\Ydb\Exceptions\Ydb\StatusCodeUnspecified::class, StatusCode::BAD_REQUEST => \YdbPlatform\Ydb\Exceptions\Ydb\BadRequestException::class,