|
25 | 25 | use Temporal\Client\Common\ClientContextTrait; |
26 | 26 | use Temporal\Client\Common\Paginator; |
27 | 27 | use Temporal\Client\GRPC\ServiceClientInterface; |
| 28 | +use Temporal\Client\Update\LifecycleStage; |
| 29 | +use Temporal\Client\Update\UpdateHandle; |
| 30 | +use Temporal\Client\Update\UpdateOptions; |
28 | 31 | use Temporal\Client\Workflow\CountWorkflowExecutions; |
29 | 32 | use Temporal\Client\Workflow\WorkflowExecutionHistory; |
30 | 33 | use Temporal\DataConverter\DataConverter; |
@@ -232,6 +235,38 @@ public function startWithSignal( |
232 | 235 | return $this->signalWithStart($workflow, $signal, $signalArgs, $startArgs); |
233 | 236 | } |
234 | 237 |
|
| 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 | + |
235 | 270 | /** |
236 | 271 | * {@inheritDoc} |
237 | 272 | */ |
|
0 commit comments