temporalio / sdk-php

Temporal PHP SDK
https://php.preview.thundergun.io
MIT License
276 stars 46 forks source link

[Feature Request] Divide Workflow stub objects and Workflow proxy objects #419

Open roxblnfk opened 7 months ago

roxblnfk commented 7 months ago

I have an idea

I suggest adjusting the Workflow Client interface: introduce a distinction between the concepts of Stub and Proxy.

Currently, as a result of calling the method WorkflowClient::newWorkflowStub($class) (or WorkflowClient::newRunningWorkflowStub($class)), we do not receive a Workflow Stub (WorkflowStubInterface), but a proxy object that redirects calls of Workflow methods related to the Workflow interface. That is, the user interacts with the proxy object as with an implementation of the user's Workflow interface.

At the same time, we have methods WorkflowClient::newUntypedWorkflowStub(), WorkflowClient::newUntypedRunningWorkflowStub(), which return the very WorkflowStubInterface (type-level guarantee). That is, they work as expected.

[!NOTE] WorkflowStubInterface is convenient when, for example, you need to call the Describe method or the Update method with your own WaitPolicy.

We face two problems:

In this commit, you can see changes in the WorkflowClientInterface interface. https://github.com/temporalio/sdk-php/commit/1847f723ff5ece0320dccfc30312da387c032b96 In the methods that currently return a Proxy, I've considered backward compatibility through the $proxy parameter. This will all be cleaned up in the next major version. Calls to create stubs with $proxy=true will throw deprecation notices.

We can also discuss replacing the naming of Stub with Handle. Then we'll just make all the *Stub methods deprecated :)

wolfy-j commented 6 months ago

@Sushisource, I propose to introduce new methods instead. Can we hop on a call to discuss it?

roxblnfk commented 6 months ago

New methods might be:

// Return WorkflowStubInterface
$wfClient->newWorkflow($class, ...);
$wfClient->newRunningWorkflow($class, ...);

// Return Proxy objects. There is `Proxy` suffix
$wfClient->newWorkflowProxy($class, ...);
$wfClient->newRunningWorkflowProxy($class, ...);

// Untyped (unknown class name). Return WorkflowStubInterface
$wfClient->newUntypedWorkflow($type, ...);
$wfClient->newUntypedRunningWorkflow($type, ...);

// DEPRECATED
$wfClient->newWorkflowStub($class, ...); // Proxy object
$wfClient->newRunningWorkflowStub($class, ...); // Proxy object
$wfClient->newUntypedWorkflowStub($type, ...); // WorkflowStubInterface
$wfClient->newUntypedRunningWorkflowStub($type, ...); // WorkflowStubInterface