Skip to content

Commit

Permalink
Add updateWithStart into WorkflowClient
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Nov 20, 2024
1 parent f642627 commit 179f1a0
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/Client/WorkflowClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
use Temporal\Client\Common\ClientContextTrait;
use Temporal\Client\Common\Paginator;
use Temporal\Client\GRPC\ServiceClientInterface;
use Temporal\Client\Update\LifecycleStage;
use Temporal\Client\Update\UpdateHandle;
use Temporal\Client\Update\UpdateOptions;
use Temporal\Client\Workflow\CountWorkflowExecutions;
use Temporal\Client\Workflow\WorkflowExecutionHistory;
use Temporal\DataConverter\DataConverter;
Expand Down Expand Up @@ -232,6 +235,38 @@ public function startWithSignal(
return $this->signalWithStart($workflow, $signal, $signalArgs, $startArgs);

Check failure on line 235 in src/Client/WorkflowClient.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)

ArgumentTypeCoercion

src/Client/WorkflowClient.php:235:50: ArgumentTypeCoercion: Argument 2 of Temporal\Client\WorkflowClient::signalWithStart expects non-empty-string, but parent type string provided (see https://psalm.dev/193)
}

public function updateWithStart(
$workflow,
string|UpdateOptions $update,
array $updateArgs = [],
array $startArgs = [],
): UpdateHandle {
$workflow instanceof WorkflowProxy && !$workflow->hasHandler() && throw new InvalidArgumentException(
'Unable to start workflow without workflow handler',
);

$update = \is_string($update) ? UpdateOptions::new($update, LifecycleStage::StageAccepted) : $update;

$workflowStub = WorkflowStubConverter::fromWorkflow($workflow);

$workflowType = $workflowStub->getWorkflowType() ?? throw new InvalidArgumentException(
'Unable to start untyped workflow without given workflowType',
);
$workflowStub->hasExecution() and throw new InvalidArgumentException(self::ERROR_WORKFLOW_START_DUPLICATION);

$handle = $this->getStarter()->updateWithStart(
$workflowType,
$workflowStub->getOptions() ?? WorkflowOptions::new(),
$update,
$updateArgs,
$startArgs,
);

$workflowStub->setExecution($handle->getExecution());

return $handle;
}

/**
* {@inheritDoc}
*/
Expand Down
25 changes: 25 additions & 0 deletions src/Client/WorkflowClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
use Temporal\Client\Common\ClientContextInterface;
use Temporal\Client\Common\Paginator;
use Temporal\Client\GRPC\ServiceClientInterface;
use Temporal\Client\Update\UpdateHandle;
use Temporal\Client\Update\UpdateOptions;
use Temporal\Client\Workflow\CountWorkflowExecutions;
use Temporal\Client\Workflow\WorkflowExecutionHistory;
use Temporal\Workflow\WorkflowExecution;
Expand Down Expand Up @@ -45,7 +47,10 @@ public function start($workflow, ...$args): WorkflowRunInterface;
* @param non-empty-string $signal
* @param array $signalArgs
* @param array $startArgs
*
* @return WorkflowRunInterface
*
* @since 2.12.0
*/
public function signalWithStart(
$workflow,
Expand All @@ -65,6 +70,26 @@ public function startWithSignal(
array $startArgs = [],
): WorkflowRunInterface;

/**
* Starts untyped and typed workflow stubs in async mode. Sends Update on start.
*
* @param object|WorkflowStubInterface $workflow
* @param non-empty-string|UpdateOptions $update Name of the update handler or update options.
* @param array $updateArgs
* @param array $startArgs
*
* @return UpdateHandle
*
* @note Experimental feature.
* @since 2.12.0
*/
public function updateWithStart(
$workflow,
string|UpdateOptions $update,
array $updateArgs = [],
array $startArgs = [],
): UpdateHandle;

/**
* Creates workflow client stub that can be used to start a single workflow execution.
*
Expand Down

0 comments on commit 179f1a0

Please sign in to comment.