Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Contrib/Grpc/GrpcTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,18 @@ final class GrpcTransport implements TransportInterface
private readonly array $metadata;
private readonly Channel $channel;
private bool $closed = false;
private Timeval $exportTimeout;

public function __construct(
string $endpoint,
array $opts,
private readonly string $method,
array $headers = [],
int $timeoutMillis = 500,
) {
$this->channel = new Channel($endpoint, $opts);
$this->metadata = $this->formatMetadata(array_change_key_case($headers));
$this->exportTimeout = new Timeval($timeoutMillis * 1000);
}

public function contentType(): string
Expand All @@ -60,7 +63,7 @@ public function send(string $payload, ?CancellationInterface $cancellation = nul
return new ErrorFuture(new BadMethodCallException('Transport closed'));
}

$call = new Call($this->channel, $this->method, Timeval::infFuture());
$call = new Call($this->channel, $this->method, $this->exportTimeout);

$cancellation ??= new NullCancellation();
$cancellationId = $cancellation->subscribe(static fn (Throwable $e) => $call->cancel());
Expand Down
2 changes: 1 addition & 1 deletion src/Contrib/Grpc/GrpcTransportFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public function create(
$opts,
$method,
$headers,
(int)($timeout * 1000),
);
}

Expand Down Expand Up @@ -116,7 +117,6 @@ private static function createOpts(
'method' => null,
],
],
'timeout' => sprintf('%0.6fs', $timeout),
'retryPolicy' => [
'maxAttempts' => $maxRetries,
'initialBackoff' => sprintf('%0.3fs', $retryDelay / 1000),
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Contrib/Grpc/GrpcTransportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ final class GrpcTransportTest extends TestCase

public function setUp(): void
{
$this->transport = new GrpcTransport('http://localhost:4317', [], '/method', []);
$this->transport = new GrpcTransport('http://localhost:4317', [], '/method', [], 123);
}

public function test_grpc_transport_supports_only_protobuf(): void
Expand Down
Loading