Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client improvements #411

Merged
merged 18 commits into from
Apr 8, 2024
Merged

Client improvements #411

merged 18 commits into from
Apr 8, 2024

Conversation

roxblnfk
Copy link
Collaborator

@roxblnfk roxblnfk commented Apr 1, 2024

Connection Management Layer

Issue #224

In the Service Client, a method getConnection() has been added, which returns a ConnectionInterface.
ConnectionInterface includes public methods isConnected(), disconnect(), connect(float $timeout), allowing
control over the connection to the Temporal server.

A gRPC connection is lazy in PHP and is established only when the first gRPC method is called.
Using the connect() method, users can immediately establish and verify connection credentials without the need for gRPC method calls.
Users can sequentially call connect() and disconnect() without causing errors related to closed gRPC channels, as the channels are recreated under the hood.

/** @var \Temporal\Client\WorkflowClient $workflowClient */

// Establish a connection with the server.
// An exception will be thrown if the connection is not established within 5 seconds.
$workflowClient->getServiceClient()->getConnection()->connect(5);

Server Capabilities info now is cached in the Connection object and will be updated on each reconnect.

/** @var \Temporal\Client\WorkflowClient $workflowClient */

// Establish a connection with the server and call getSystemInfo() RPC method.
$capabilities = $workflowClient->getServiceClient()->getServerCapabilities();

if (!$capabilities?->supportsSchedules) } {
    throw new \Temporal\Exception\TemporalException('Server does not support schedules');
}

Service Client with Secure Connection

A deprecation error will now be triggered when a ServiceClient is created directly through the constructor. Static factories are the only recommended way to create a ServiceClient.

One of such static methods has changes:
in ServiceClient::createSSL(), the root certificate parameter has been made optional because it should be skipped when connecting to the Temporal Cloud.
All keys can be passed as a string payload (previously, only by file name was allowed). If the provided file cannot be read, a clear exception will be thrown.

New methods for all the Client (Workflow and Schedule)

Issue #338

Added new methods to WorkflowClient, ScheduleClient and ScheduleHandle:

  • withTimeout(float $timeout)
  • withDeadline()
  • withRetryOptions()
  • withMetadata()

They may be used before calling any method that sends a gRPC request to the server.

/** @var \Temporal\Client\ScheduleClient $scheduleClient */

$list = $scheduleClient->withTimeout(5)->listSchedules();

All the new methods are immutable and return a new instance of the client that will use the same connection as the original client, but with the specified timeout, deadline or retry options.

/** @var \Temporal\Client\WorkflowClient $workflowClient */

// All the calls $workflow->* will be executed with a 5-second timeout.
$workflow = $workflowClient->withTimeout(5)->newWorkflowStub(MyWorkflow::class);

// Will be called with a 10-second timeout.
$workflowClient->withTimeout(10)->start($workflow, 'foo', 'bar')

// Will be called with a 5-second timeout because the stub was created with a 5-second timeout client.
$workflow->signal();

Note: WorkflowClientInterface and ScheduleClientInterface have been updated with the new methods.

Namespace Inheritance in Client methods

A mistake was made in the implementation of several client functions last time: instead of using the Namespace value from ClientOptions, a parameter with the default value "default" was used.
This complicates the use of Temporal Cloud, where user's Namespace differs from "default".

Affected methods are:

  • WorkflowClient::listWorkflowExecutions()
  • WorkflowClient::countWorkflowExecutions()
  • WorkflowClient::getWorkflowHistory()
  • ScheduleClient::getHandle()

The $namespace parameter is now null by default. If a method receives null, the Namespace from ClientOptions will be used.

Other changes

  • The immutability attribute has been removed from all interceptor interfaces.
  • Fixed SystemInfoInterceptor constructor parameter: ConnectionInterface instead of ServiceClient.
  • In SystemInfoInterceptor, new features related to caching Server Capabilities inside the Connection are considered.
  • ServiceClient::setServerCapabilities() method has been removed from the ServiceClientInterface. The implementing method just triggers a deprecation error.
  • ServiceClient::getServerCapabilities() method now loads the Server Capabilities from the Connection object instead of just returning the cached value.
  • Updated ServerCapabilities DTO: added all the new fields; the flags are available as public properties.
  • Move Workflow\Client\CountWorkflowExecutions, Workflow\Client\Paginator and Workflow\Client\ServerCapabilities into other namespaces.

@roxblnfk roxblnfk added Bug Something isn't working Feature New feature or request labels Apr 1, 2024
@roxblnfk roxblnfk added this to the 2.9.0 milestone Apr 1, 2024
Copy link
Member

@Sushisource Sushisource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't do a detailed code review, but conceptually everything you have in your PR description makes sense to me. Thanks!

@roxblnfk roxblnfk merged commit c13912c into master Apr 8, 2024
90 checks passed
@roxblnfk roxblnfk deleted the client-improvements branch April 8, 2024 19:48
@roxblnfk roxblnfk restored the client-improvements branch April 8, 2024 19:50
@roxblnfk roxblnfk deleted the client-improvements branch April 9, 2024 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add an ability to set timeout for all client calls Lazy connectivity for Temporal client and healthCheck
3 participants