Skip to content

Commit 88ab2fd

Browse files
authored
Merge branch 'master' into fix-yielded-generator
2 parents 0b43136 + 001cfe1 commit 88ab2fd

33 files changed

+794
-133
lines changed

psalm-baseline.xml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@
123123
<file src="src/Client/WorkflowClient.php">
124124
<ArgumentTypeCoercion>
125125
<code><![CDATA[$counter]]></code>
126+
<code><![CDATA[$signal]]></code>
126127
<code><![CDATA[$workflowType]]></code>
127128
<code><![CDATA[$workflowType]]></code>
128129
</ArgumentTypeCoercion>
@@ -148,13 +149,24 @@
148149
<LessSpecificReturnStatement>
149150
<code><![CDATA[new self($serviceClient, $options, $converter, $interceptorProvider)]]></code>
150151
</LessSpecificReturnStatement>
152+
<MissingParamType>
153+
<code><![CDATA[$workflow]]></code>
154+
</MissingParamType>
151155
<MoreSpecificReturnType>
152156
<code><![CDATA[static]]></code>
153157
</MoreSpecificReturnType>
154158
<RedundantFunctionCall>
155159
<code><![CDATA[\sprintf]]></code>
156160
<code><![CDATA[\sprintf]]></code>
157161
</RedundantFunctionCall>
162+
<TypeDoesNotContainType>
163+
<code><![CDATA[$signal === '']]></code>
164+
</TypeDoesNotContainType>
165+
</file>
166+
<file src="src/Client/WorkflowClientInterface.php">
167+
<MissingParamType>
168+
<code><![CDATA[$workflow]]></code>
169+
</MissingParamType>
158170
</file>
159171
<file src="src/Client/WorkflowOptions.php">
160172
<ImpureMethodCall>
@@ -384,6 +396,14 @@
384396
</MissingParamType>
385397
</file>
386398
<file src="src/Internal/Client/WorkflowStarter.php">
399+
<InvalidArgument>
400+
<code><![CDATA[0]]></code>
401+
<code><![CDATA[1]]></code>
402+
<code><![CDATA[1]]></code>
403+
</InvalidArgument>
404+
<MissingTemplateParam>
405+
<code><![CDATA[$fails]]></code>
406+
</MissingTemplateParam>
387407
<PossiblyNullArgument>
388408
<code><![CDATA[$options->retryOptions ? $options->retryOptions->toWorkflowRetryPolicy() : null]]></code>
389409
<code><![CDATA[$options->toMemo($this->converter)]]></code>
@@ -395,6 +415,9 @@
395415
<RedundantConditionGivenDocblockType>
396416
<code><![CDATA[$delay !== null]]></code>
397417
</RedundantConditionGivenDocblockType>
418+
<UndefinedInterfaceMethod>
419+
<code><![CDATA[toHeader]]></code>
420+
</UndefinedInterfaceMethod>
398421
</file>
399422
<file src="src/Internal/Client/WorkflowStub.php">
400423
<PossiblyInvalidArgument>
@@ -405,6 +428,7 @@
405428
<code><![CDATA[$attr->getFailure()]]></code>
406429
<code><![CDATA[$attr->getResult()]]></code>
407430
<code><![CDATA[$input->workflowType]]></code>
431+
<code><![CDATA[$input->workflowType]]></code>
408432
<code><![CDATA[$result->getQueryResult()]]></code>
409433
<code><![CDATA[$this->execution]]></code>
410434
<code><![CDATA[$this->execution]]></code>

src/Client/Common/ServerCapabilities.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ final class ServerCapabilities
4343
* it in history
4444
* @param bool $countGroupByExecutionStatus
4545
* True if the server supports count group by execution status
46-
* (-- api-linter: core::0140::prepositions=disabled --)
46+
* @param bool $nexus
47+
* True if the server supports Nexus operations.
48+
* This flag is dependent both on server version and for Nexus to be enabled via server configuration.
4749
*/
4850
public function __construct(
4951
public readonly bool $signalAndQueryHeader = false,
@@ -56,6 +58,7 @@ public function __construct(
5658
public readonly bool $eagerWorkflowStart = false,
5759
public readonly bool $sdkMetadata = false,
5860
public readonly bool $countGroupByExecutionStatus = false,
61+
public readonly bool $nexus = false,
5962
) {}
6063

6164
/**

src/Client/GRPC/BaseClient.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public function getServerCapabilities(): ?ServerCapabilities
199199
eagerWorkflowStart: $capabilities->getEagerWorkflowStart(),
200200
sdkMetadata: $capabilities->getSdkMetadata(),
201201
countGroupByExecutionStatus: $capabilities->getCountGroupByExecutionStatus(),
202+
nexus: $capabilities->getNexus(),
202203
);
203204
} catch (ServiceClientException $e) {
204205
if ($e->getCode() === StatusCode::UNIMPLEMENTED) {

src/Client/GRPC/ServiceClient.php

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,29 @@ public function StartWorkflowExecution(V1\StartWorkflowExecutionRequest $arg, ?C
102102
return $this->invoke("StartWorkflowExecution", $arg, $ctx);
103103
}
104104

105+
/**
106+
* ExecuteMultiOperation executes multiple operations within a single workflow.
107+
*
108+
* Operations are started atomically, meaning if *any* operation fails to be
109+
* started, none are,
110+
* and the request fails. Upon start, the API returns only when *all* operations
111+
* have a response.
112+
*
113+
* Upon failure, it returns `MultiOperationExecutionFailure` where the status code
114+
* equals the status code of the *first* operation that failed to be started.
115+
*
116+
* NOTE: Experimental API.
117+
*
118+
* @param V1\ExecuteMultiOperationRequest $arg
119+
* @param ContextInterface|null $ctx
120+
* @return V1\ExecuteMultiOperationResponse
121+
* @throws ServiceClientException
122+
*/
123+
public function ExecuteMultiOperation(V1\ExecuteMultiOperationRequest $arg, ?ContextInterface $ctx = null): V1\ExecuteMultiOperationResponse
124+
{
125+
return $this->invoke("ExecuteMultiOperation", $arg, $ctx);
126+
}
127+
105128
/**
106129
* GetWorkflowExecutionHistory returns the history of specified workflow execution.
107130
* Fails with
@@ -777,8 +800,40 @@ public function GetWorkerBuildIdCompatibility(V1\GetWorkerBuildIdCompatibilityRe
777800
}
778801

779802
/**
780-
* Allows updating the Build ID assignment and redirect rules for a given Task
781-
* Queue.
803+
* Use this API to manage Worker Versioning Rules for a given Task Queue. There are
804+
* two types of
805+
* rules: Build ID Assignment rules and Compatible Build ID Redirect rules.
806+
*
807+
* Assignment rules determine how to assign new executions to a Build IDs. Their
808+
* primary
809+
* use case is to specify the latest Build ID but they have powerful features for
810+
* gradual rollout
811+
* of a new Build ID.
812+
*
813+
* Once a workflow execution is assigned to a Build ID and it completes its first
814+
* Workflow Task,
815+
* the workflow stays on the assigned Build ID regardless of changes in assignment
816+
* rules. This
817+
* eliminates the need for compatibility between versions when you only care about
818+
* using the new
819+
* version for new workflows and let existing workflows finish in their own
820+
* version.
821+
*
822+
* Activities, Child Workflows and Continue-as-New executions have the option to
823+
* inherit the
824+
* Build ID of their parent/previous workflow or use the latest assignment rules to
825+
* independently
826+
* select a Build ID.
827+
*
828+
* Redirect rules should only be used when you want to move workflows and
829+
* activities assigned to
830+
* one Build ID (source) to another compatible Build ID (target). You are
831+
* responsible to make sure
832+
* the target Build ID of a redirect rule is able to process event histories made
833+
* by the source
834+
* Build ID by using [Patching](https://docs.temporal.io/workflows#patching) or
835+
* other means.
836+
*
782837
* WARNING: Worker Versioning is not yet stable and the API and behavior may change
783838
* incompatibly.
784839
* (-- api-linter: core::0127::http-annotation=disabled

src/Client/GRPC/ServiceClientInterface.php

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,25 @@ public function DeprecateNamespace(V1\DeprecateNamespaceRequest $arg, ContextInt
100100
* @throws ServiceClientException
101101
*/
102102
public function StartWorkflowExecution(V1\StartWorkflowExecutionRequest $arg, ContextInterface $ctx = null) : V1\StartWorkflowExecutionResponse;
103+
/**
104+
* ExecuteMultiOperation executes multiple operations within a single workflow.
105+
*
106+
* Operations are started atomically, meaning if *any* operation fails to be
107+
* started, none are,
108+
* and the request fails. Upon start, the API returns only when *all* operations
109+
* have a response.
110+
*
111+
* Upon failure, it returns `MultiOperationExecutionFailure` where the status code
112+
* equals the status code of the *first* operation that failed to be started.
113+
*
114+
* NOTE: Experimental API.
115+
*
116+
* @param V1\ExecuteMultiOperationRequest $arg
117+
* @param ContextInterface|null $ctx
118+
* @return V1\ExecuteMultiOperationResponse
119+
* @throws ServiceClientException
120+
*/
121+
public function ExecuteMultiOperation(V1\ExecuteMultiOperationRequest $arg, ContextInterface $ctx = null) : V1\ExecuteMultiOperationResponse;
103122
/**
104123
* GetWorkflowExecutionHistory returns the history of specified workflow execution.
105124
* Fails with
@@ -731,8 +750,40 @@ public function UpdateWorkerBuildIdCompatibility(V1\UpdateWorkerBuildIdCompatibi
731750
*/
732751
public function GetWorkerBuildIdCompatibility(V1\GetWorkerBuildIdCompatibilityRequest $arg, ContextInterface $ctx = null) : V1\GetWorkerBuildIdCompatibilityResponse;
733752
/**
734-
* Allows updating the Build ID assignment and redirect rules for a given Task
735-
* Queue.
753+
* Use this API to manage Worker Versioning Rules for a given Task Queue. There are
754+
* two types of
755+
* rules: Build ID Assignment rules and Compatible Build ID Redirect rules.
756+
*
757+
* Assignment rules determine how to assign new executions to a Build IDs. Their
758+
* primary
759+
* use case is to specify the latest Build ID but they have powerful features for
760+
* gradual rollout
761+
* of a new Build ID.
762+
*
763+
* Once a workflow execution is assigned to a Build ID and it completes its first
764+
* Workflow Task,
765+
* the workflow stays on the assigned Build ID regardless of changes in assignment
766+
* rules. This
767+
* eliminates the need for compatibility between versions when you only care about
768+
* using the new
769+
* version for new workflows and let existing workflows finish in their own
770+
* version.
771+
*
772+
* Activities, Child Workflows and Continue-as-New executions have the option to
773+
* inherit the
774+
* Build ID of their parent/previous workflow or use the latest assignment rules to
775+
* independently
776+
* select a Build ID.
777+
*
778+
* Redirect rules should only be used when you want to move workflows and
779+
* activities assigned to
780+
* one Build ID (source) to another compatible Build ID (target). You are
781+
* responsible to make sure
782+
* the target Build ID of a redirect rule is able to process event histories made
783+
* by the source
784+
* Build ID by using [Patching](https://docs.temporal.io/workflows#patching) or
785+
* other means.
786+
*
736787
* WARNING: Worker Versioning is not yet stable and the API and behavior may change
737788
* incompatibly.
738789
* (-- api-linter: core::0127::http-annotation=disabled

src/Client/WorkflowClient.php

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Temporal\Client;
1313

1414
use Doctrine\Common\Annotations\Reader;
15+
use JetBrains\PhpStorm\Deprecated;
1516
use Spiral\Attributes\AnnotationReader;
1617
use Spiral\Attributes\AttributeReader;
1718
use Spiral\Attributes\Composite\SelectiveReader;
@@ -24,6 +25,9 @@
2425
use Temporal\Client\Common\ClientContextTrait;
2526
use Temporal\Client\Common\Paginator;
2627
use Temporal\Client\GRPC\ServiceClientInterface;
28+
use Temporal\Client\Update\LifecycleStage;
29+
use Temporal\Client\Update\UpdateHandle;
30+
use Temporal\Client\Update\UpdateOptions;
2731
use Temporal\Client\Workflow\CountWorkflowExecutions;
2832
use Temporal\Client\Workflow\WorkflowExecutionHistory;
2933
use Temporal\DataConverter\DataConverter;
@@ -144,10 +148,7 @@ public function start($workflow, ...$args): WorkflowRunInterface
144148
);
145149
}
146150

147-
/**
148-
* @param object|WorkflowStubInterface $workflow
149-
*/
150-
public function startWithSignal(
151+
public function signalWithStart(
151152
$workflow,
152153
string $signal,
153154
array $signalArgs = [],
@@ -205,6 +206,50 @@ public function startWithSignal(
205206
);
206207
}
207208

209+
#[Deprecated(replacement: '%class%->signalWithStart(%parametersList%)')]
210+
public function startWithSignal(
211+
$workflow,
212+
string $signal,
213+
array $signalArgs = [],
214+
array $startArgs = [],
215+
): WorkflowRunInterface {
216+
return $this->signalWithStart($workflow, $signal, $signalArgs, $startArgs);
217+
}
218+
219+
public function updateWithStart(
220+
$workflow,
221+
string|UpdateOptions $update,
222+
array $updateArgs = [],
223+
array $startArgs = [],
224+
): UpdateHandle {
225+
$workflow instanceof WorkflowProxy && !$workflow->hasHandler() && throw new InvalidArgumentException(
226+
'Unable to start workflow without workflow handler',
227+
);
228+
229+
$update = \is_string($update) ? UpdateOptions::new($update, LifecycleStage::StageAccepted) : $update;
230+
231+
$workflowStub = WorkflowStubConverter::fromWorkflow($workflow);
232+
233+
$workflowType = $workflowStub->getWorkflowType() ?? throw new InvalidArgumentException(
234+
'Unable to start untyped workflow without given workflowType',
235+
);
236+
$workflowStub->hasExecution() and throw new InvalidArgumentException(self::ERROR_WORKFLOW_START_DUPLICATION);
237+
238+
[$execution, $handle] = $this->getStarter()->updateWithStart(
239+
$workflowType,
240+
$workflowStub->getOptions() ?? WorkflowOptions::new(),
241+
$update,
242+
$updateArgs,
243+
$startArgs,
244+
);
245+
246+
$workflowStub->setExecution($execution);
247+
248+
return $handle instanceof \Throwable
249+
? throw $handle
250+
: $handle;
251+
}
252+
208253
public function newWorkflowStub(
209254
string $class,
210255
?WorkflowOptions $options = null,

src/Client/WorkflowClientInterface.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@
1111

1212
namespace Temporal\Client;
1313

14+
use JetBrains\PhpStorm\Deprecated;
1415
use Temporal\Api\Enums\V1\HistoryEventFilterType;
1516
use Temporal\Client\Common\ClientContextInterface;
1617
use Temporal\Client\Common\Paginator;
1718
use Temporal\Client\GRPC\ServiceClientInterface;
19+
use Temporal\Client\Update\UpdateHandle;
20+
use Temporal\Client\Update\UpdateOptions;
1821
use Temporal\Client\Workflow\CountWorkflowExecutions;
1922
use Temporal\Client\Workflow\WorkflowExecutionHistory;
2023
use Temporal\Workflow\WorkflowExecution;
@@ -37,14 +40,48 @@ public function start($workflow, ...$args): WorkflowRunInterface;
3740
* Starts untyped and typed workflow stubs in async mode. Sends signal on start.
3841
*
3942
* @param object|WorkflowStubInterface $workflow
43+
* @param non-empty-string $signal
44+
*
45+
* @since 2.12.0
46+
*/
47+
public function signalWithStart(
48+
$workflow,
49+
string $signal,
50+
array $signalArgs = [],
51+
array $startArgs = [],
52+
): WorkflowRunInterface;
53+
54+
/**
55+
* @deprecated Use {@see self::signalWithStart()} instead.
4056
*/
57+
#[Deprecated(replacement: '%class%->signalWithStart(%parametersList%)')]
4158
public function startWithSignal(
4259
$workflow,
4360
string $signal,
4461
array $signalArgs = [],
4562
array $startArgs = [],
4663
): WorkflowRunInterface;
4764

65+
/**
66+
* Starts untyped and typed workflow stubs in async mode. Sends Update on start.
67+
*
68+
* @param object|WorkflowStubInterface $workflow
69+
* @param non-empty-string|UpdateOptions $update Name of the update handler or update options.
70+
* @param array $updateArgs
71+
* @param array $startArgs
72+
*
73+
* @return UpdateHandle
74+
*
75+
* @note Experimental feature.
76+
* @since 2.12.0
77+
*/
78+
public function updateWithStart(
79+
$workflow,
80+
string|UpdateOptions $update,
81+
array $updateArgs = [],
82+
array $startArgs = [],
83+
): UpdateHandle;
84+
4885
/**
4986
* Creates workflow client stub that can be used to start a single workflow execution.
5087
*

src/Client/WorkflowOptions.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,6 @@ public function __construct()
163163
}
164164

165165
/**
166-
*
167166
* @return self return a new {@see self} instance with merged options
168167
*/
169168
public function mergeWith(?MethodRetry $retry = null, ?CronSchedule $cron = null): self

src/Client/WorkflowStubInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
*/
3333
interface WorkflowStubInterface extends WorkflowRunInterface
3434
{
35+
/**
36+
* @return non-empty-string|null
37+
*/
3538
public function getWorkflowType(): ?string;
3639

3740
/**

0 commit comments

Comments
 (0)