sdk-php icon indicating copy to clipboard operation
sdk-php copied to clipboard

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

Open roxblnfk opened this issue 1 year ago • 2 comments

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:

  • methods with the Stub postfix work differently: two out of four return WorkflowStubInterface, the other two return a proxy.
  • there is no proper way to get WorkflowStubInterface from a Workflow class. Both methods that accept a class return us a proxy.

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 :)

roxblnfk avatar Apr 12 '24 13:04 roxblnfk

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

wolfy-j avatar Apr 16 '24 14:04 wolfy-j

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

roxblnfk avatar Apr 16 '24 14:04 roxblnfk