Skip to content

Commit 179f1a0

Browse files
committed
Add updateWithStart into WorkflowClient
1 parent f642627 commit 179f1a0

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

src/Client/WorkflowClient.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
use Temporal\Client\Common\ClientContextTrait;
2626
use Temporal\Client\Common\Paginator;
2727
use Temporal\Client\GRPC\ServiceClientInterface;
28+
use Temporal\Client\Update\LifecycleStage;
29+
use Temporal\Client\Update\UpdateHandle;
30+
use Temporal\Client\Update\UpdateOptions;
2831
use Temporal\Client\Workflow\CountWorkflowExecutions;
2932
use Temporal\Client\Workflow\WorkflowExecutionHistory;
3033
use Temporal\DataConverter\DataConverter;
@@ -232,6 +235,38 @@ public function startWithSignal(
232235
return $this->signalWithStart($workflow, $signal, $signalArgs, $startArgs);
233236
}
234237

238+
public function updateWithStart(
239+
$workflow,
240+
string|UpdateOptions $update,
241+
array $updateArgs = [],
242+
array $startArgs = [],
243+
): UpdateHandle {
244+
$workflow instanceof WorkflowProxy && !$workflow->hasHandler() && throw new InvalidArgumentException(
245+
'Unable to start workflow without workflow handler',
246+
);
247+
248+
$update = \is_string($update) ? UpdateOptions::new($update, LifecycleStage::StageAccepted) : $update;
249+
250+
$workflowStub = WorkflowStubConverter::fromWorkflow($workflow);
251+
252+
$workflowType = $workflowStub->getWorkflowType() ?? throw new InvalidArgumentException(
253+
'Unable to start untyped workflow without given workflowType',
254+
);
255+
$workflowStub->hasExecution() and throw new InvalidArgumentException(self::ERROR_WORKFLOW_START_DUPLICATION);
256+
257+
$handle = $this->getStarter()->updateWithStart(
258+
$workflowType,
259+
$workflowStub->getOptions() ?? WorkflowOptions::new(),
260+
$update,
261+
$updateArgs,
262+
$startArgs,
263+
);
264+
265+
$workflowStub->setExecution($handle->getExecution());
266+
267+
return $handle;
268+
}
269+
235270
/**
236271
* {@inheritDoc}
237272
*/

src/Client/WorkflowClientInterface.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Temporal\Client\Common\ClientContextInterface;
1717
use Temporal\Client\Common\Paginator;
1818
use Temporal\Client\GRPC\ServiceClientInterface;
19+
use Temporal\Client\Update\UpdateHandle;
20+
use Temporal\Client\Update\UpdateOptions;
1921
use Temporal\Client\Workflow\CountWorkflowExecutions;
2022
use Temporal\Client\Workflow\WorkflowExecutionHistory;
2123
use Temporal\Workflow\WorkflowExecution;
@@ -45,7 +47,10 @@ public function start($workflow, ...$args): WorkflowRunInterface;
4547
* @param non-empty-string $signal
4648
* @param array $signalArgs
4749
* @param array $startArgs
50+
*
4851
* @return WorkflowRunInterface
52+
*
53+
* @since 2.12.0
4954
*/
5055
public function signalWithStart(
5156
$workflow,
@@ -65,6 +70,26 @@ public function startWithSignal(
6570
array $startArgs = [],
6671
): WorkflowRunInterface;
6772

73+
/**
74+
* Starts untyped and typed workflow stubs in async mode. Sends Update on start.
75+
*
76+
* @param object|WorkflowStubInterface $workflow
77+
* @param non-empty-string|UpdateOptions $update Name of the update handler or update options.
78+
* @param array $updateArgs
79+
* @param array $startArgs
80+
*
81+
* @return UpdateHandle
82+
*
83+
* @note Experimental feature.
84+
* @since 2.12.0
85+
*/
86+
public function updateWithStart(
87+
$workflow,
88+
string|UpdateOptions $update,
89+
array $updateArgs = [],
90+
array $startArgs = [],
91+
): UpdateHandle;
92+
6893
/**
6994
* Creates workflow client stub that can be used to start a single workflow execution.
7095
*

0 commit comments

Comments
 (0)