-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Temporal package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Client\Interceptor; | ||
|
||
use Temporal\Api\Workflowservice\V1\GetSystemInfoRequest; | ||
use Temporal\Client\GRPC\ContextInterface; | ||
use Temporal\Client\GRPC\ServiceClient; | ||
use Temporal\Client\GRPC\StatusCode; | ||
use Temporal\Client\ServerCapabilities; | ||
use Temporal\Exception\Client\ServiceClientException; | ||
use Temporal\Interceptor\GrpcClientInterceptor; | ||
|
||
/** | ||
* @psalm-immutable | ||
*/ | ||
final class SystemInfoInterceptor implements GrpcClientInterceptor | ||
{ | ||
private bool $systemInfoRequested = false; | ||
|
||
public function __construct( | ||
private ServiceClient $serviceClient | ||
) { | ||
} | ||
|
||
/** | ||
* @param non-empty-string $method | ||
* @param callable(non-empty-string, object, ContextInterface): object $next | ||
*/ | ||
public function interceptCall(string $method, object $arg, ContextInterface $ctx, callable $next): object | ||
{ | ||
if ($this->systemInfoRequested) { | ||
return $next($method, $arg, $ctx); | ||
Check failure on line 41 in src/Client/Interceptor/SystemInfoInterceptor.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)ImpureFunctionCall
|
||
} | ||
|
||
try { | ||
$systemInfo = $this->serviceClient->getSystemInfo(new GetSystemInfoRequest()); | ||
Check failure on line 45 in src/Client/Interceptor/SystemInfoInterceptor.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)ImpureMethodCall
|
||
|
||
$capabilities = $systemInfo->getCapabilities(); | ||
Check failure on line 47 in src/Client/Interceptor/SystemInfoInterceptor.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)ImpureMethodCall
|
||
if ($capabilities !== null && $this->serviceClient->getServerCapabilities() === null) { | ||
$this->serviceClient->setServerCapabilities(new ServerCapabilities( | ||
Check failure on line 49 in src/Client/Interceptor/SystemInfoInterceptor.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)ImpureMethodCall
|
||
signalAndQueryHeader: $capabilities->getSignalAndQueryHeader(), | ||
Check failure on line 50 in src/Client/Interceptor/SystemInfoInterceptor.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)ImpureMethodCall
|
||
internalErrorDifferentiation: $capabilities->getInternalErrorDifferentiation() | ||
Check failure on line 51 in src/Client/Interceptor/SystemInfoInterceptor.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)ImpureMethodCall
|
||
)); | ||
} | ||
} catch (ServiceClientException $e) { | ||
if ($e->getCode() !== StatusCode::UNIMPLEMENTED) { | ||
throw $e; | ||
} | ||
} | ||
|
||
$this->systemInfoRequested = true; | ||
Check failure on line 60 in src/Client/Interceptor/SystemInfoInterceptor.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)InaccessibleProperty
|
||
|
||
return $next($method, $arg, $ctx); | ||
Check failure on line 62 in src/Client/Interceptor/SystemInfoInterceptor.php GitHub Actions / Psalm Validation (PHP 8.2, OS ubuntu-latest)ImpureFunctionCall
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of Temporal package. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Client; | ||
|
||
final class ServerCapabilities | ||
{ | ||
public function __construct( | ||
private bool $signalAndQueryHeader = false, | ||
private bool $internalErrorDifferentiation = false | ||
) { | ||
} | ||
|
||
/** | ||
* True if signal and query headers are supported. | ||
*/ | ||
public function isSignalAndQueryHeaderSupports(): bool | ||
{ | ||
return $this->signalAndQueryHeader; | ||
} | ||
|
||
/** | ||
* True if internal errors are differentiated from other types of errors for purposes of | ||
* retrying non-internal errors. | ||
* When unset/false, clients retry all failures. When true, clients should only retry | ||
* non-internal errors. | ||
*/ | ||
public function isInternalErrorDifferentiation(): bool | ||
{ | ||
return $this->internalErrorDifferentiation; | ||
} | ||
} |