Skip to content

Commit bd24c8d

Browse files
authored
Merge pull request #585: Support UserMetadata in Client API
2 parents ac9e858 + f5561d7 commit bd24c8d

27 files changed

Lines changed: 626 additions & 99 deletions

psalm-baseline.xml

Lines changed: 58 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="6.8.8@1361cd33008feb3ae2b4a93f1860e14e538ec8c2">
2+
<files psalm-version="6.9.1@81c8a77c0793d450fee40265cfe68891df11d505">
33
<file src="src/Activity.php">
44
<ImplicitToStringCast>
55
<code><![CDATA[$type]]></code>
@@ -45,12 +45,23 @@
4545
<code><![CDATA[$loader->current()]]></code>
4646
</PossiblyNullPropertyAssignmentValue>
4747
</file>
48+
<file src="src/Client/Common/RpcRetryOptions.php">
49+
<TypeDoesNotContainType>
50+
<code><![CDATA[withInitialInterval]]></code>
51+
<code><![CDATA[withMaximumInterval]]></code>
52+
</TypeDoesNotContainType>
53+
</file>
4854
<file src="src/Client/GRPC/Context.php">
4955
<ArgumentTypeCoercion>
5056
<code><![CDATA[$format]]></code>
5157
</ArgumentTypeCoercion>
5258
</file>
5359
<file src="src/Client/Schedule/Action/StartWorkflowAction.php">
60+
<DocblockTypeContradiction>
61+
<code><![CDATA[parse]]></code>
62+
<code><![CDATA[parse]]></code>
63+
<code><![CDATA[parse]]></code>
64+
</DocblockTypeContradiction>
5465
<InaccessibleProperty>
5566
<code><![CDATA[$workflowType->name]]></code>
5667
</InaccessibleProperty>
@@ -114,6 +125,9 @@
114125
<code><![CDATA[$this->excludeCalendarList]]></code>
115126
<code><![CDATA[$this->excludeCalendarList]]></code>
116127
</DeprecatedProperty>
128+
<DocblockTypeContradiction>
129+
<code><![CDATA[parse]]></code>
130+
</DocblockTypeContradiction>
117131
</file>
118132
<file src="src/Client/ScheduleClient.php">
119133
<DeprecatedProperty>
@@ -442,19 +456,11 @@
442456
<MissingTemplateParam>
443457
<code><![CDATA[$fails]]></code>
444458
</MissingTemplateParam>
445-
<PossiblyNullArgument>
446-
<code><![CDATA[$options->retryOptions ? $options->retryOptions->toWorkflowRetryPolicy() : null]]></code>
447-
<code><![CDATA[$options->toMemo($this->converter)]]></code>
448-
<code><![CDATA[$options->toSearchAttributes($this->converter)]]></code>
449-
</PossiblyNullArgument>
450459
<PossiblyNullReference>
451460
<code><![CDATA[getName]]></code>
452461
<code><![CDATA[getStartWorkflow]]></code>
453462
<code><![CDATA[getUpdateWorkflow]]></code>
454463
</PossiblyNullReference>
455-
<RedundantConditionGivenDocblockType>
456-
<code><![CDATA[$delay !== null]]></code>
457-
</RedundantConditionGivenDocblockType>
458464
<UndefinedInterfaceMethod>
459465
<code><![CDATA[toHeader]]></code>
460466
</UndefinedInterfaceMethod>
@@ -670,12 +676,34 @@
670676
<code><![CDATA[setDataConverter]]></code>
671677
</UndefinedInterfaceMethod>
672678
</file>
679+
<file src="src/Internal/Mapper/WorkflowExecutionConfigMapper.php">
680+
<DocblockTypeContradiction>
681+
<code><![CDATA[parse]]></code>
682+
<code><![CDATA[parse]]></code>
683+
<code><![CDATA[parse]]></code>
684+
<code><![CDATA[parse]]></code>
685+
<code><![CDATA[parse]]></code>
686+
</DocblockTypeContradiction>
687+
<RedundantConditionGivenDocblockType>
688+
<code><![CDATA[parse]]></code>
689+
</RedundantConditionGivenDocblockType>
690+
</file>
673691
<file src="src/Internal/Mapper/WorkflowExecutionInfoMapper.php">
674692
<ArgumentTypeCoercion>
675693
<code><![CDATA[$message->getTaskQueue()]]></code>
676694
<code><![CDATA[(int) $message->getHistorySizeBytes()]]></code>
677695
<code><![CDATA[(int) $message->getStateTransitionCount()]]></code>
678696
</ArgumentTypeCoercion>
697+
<DocblockTypeContradiction>
698+
<code><![CDATA[parse]]></code>
699+
<code><![CDATA[parse]]></code>
700+
<code><![CDATA[parse]]></code>
701+
<code><![CDATA[parse]]></code>
702+
<code><![CDATA[parse]]></code>
703+
</DocblockTypeContradiction>
704+
<RedundantConditionGivenDocblockType>
705+
<code><![CDATA[parse]]></code>
706+
</RedundantConditionGivenDocblockType>
679707
</file>
680708
<file src="src/Internal/Marshaller/Mapper/AttributeMapper.php">
681709
<MissingClosureParamType>
@@ -749,8 +777,15 @@
749777
<code><![CDATA[$mapper]]></code>
750778
</LessSpecificReturnStatement>
751779
<MoreSpecificReturnType>
752-
<code><![CDATA[null|\Closure(Message): mixed]]></code>
780+
<code><![CDATA[\Closure(Message): mixed]]></code>
753781
</MoreSpecificReturnType>
782+
<NullableReturnStatement>
783+
<code><![CDATA[$mapper]]></code>
784+
</NullableReturnStatement>
785+
<PossiblyNullArgument>
786+
<code><![CDATA[$metadata->getDetails()]]></code>
787+
<code><![CDATA[$metadata->getSummary()]]></code>
788+
</PossiblyNullArgument>
754789
</file>
755790
<file src="src/Internal/Marshaller/Type/ArrayType.php">
756791
<MoreSpecificImplementedParamType>
@@ -871,6 +906,19 @@
871906
<code><![CDATA[self::FORMAT_MONTHS]]></code>
872907
<code><![CDATA[self::FORMAT_YEARS]]></code>
873908
</DeprecatedConstant>
909+
<RedundantCondition>
910+
<code><![CDATA[$nullEmpty && $seconds === 0 && $micros === 0]]></code>
911+
<code><![CDATA[parse]]></code>
912+
</RedundantCondition>
913+
<TypeDoesNotContainNull>
914+
<code><![CDATA[parse]]></code>
915+
</TypeDoesNotContainNull>
916+
<TypeDoesNotContainType>
917+
<code><![CDATA[parse]]></code>
918+
<code><![CDATA[parse]]></code>
919+
<code><![CDATA[parse]]></code>
920+
<code><![CDATA[parse]]></code>
921+
</TypeDoesNotContainType>
874922
</file>
875923
<file src="src/Internal/Support/DateTime.php">
876924
<InvalidReturnStatement>

src/Client/Common/RpcRetryOptions.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ public static function fromRetryOptions(RetryOptions $options): self
4848
* Interval of the first retry, on congestion related failures (i.e. RESOURCE_EXHAUSTED errors).
4949
* If coefficient is 1.0 then it is used for all retries. Defaults to 1000ms.
5050
*
51-
* @param DateIntervalValue|null $interval Interval to wait on first retry, on congestion failures.
51+
* @param mixed $interval Interval to wait on first retry, on congestion failures.
5252
* Defaults to 1000ms, which is used if set to {@see null}.
53+
* Can be parseable string, int|float in seconds, {@see \DateInterval}, or {@see Duration}
54+
* @return static
5355
*
56+
* @psalm-assert DateIntervalValue|null $interval
5457
* @psalm-suppress ImpureMethodCall
5558
*/
5659
#[Pure]
57-
public function withCongestionInitialInterval($interval): self
60+
public function withCongestionInitialInterval(mixed $interval): self
5861
{
5962
$interval === null || DateInterval::assert($interval) or throw new \InvalidArgumentException(
6063
'Invalid interval value.',

src/Client/Schedule/Action/StartWorkflowAction.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Temporal\Api\Common\V1\Header;
99
use Temporal\Api\Common\V1\Memo;
1010
use Temporal\Api\Common\V1\SearchAttributes;
11+
use Temporal\Client\Workflow\UserMetadata;
1112
use Temporal\Common\IdReusePolicy;
1213
use Temporal\Common\RetryOptions;
1314
use Temporal\Common\TaskQueue\TaskQueue;
@@ -108,6 +109,13 @@ final class StartWorkflowAction extends ScheduleAction
108109
#[Marshal(type: EncodedCollectionType::class, of: Header::class)]
109110
public readonly HeaderInterface $header;
110111

112+
/**
113+
* @internal
114+
* @experimental This feature is not stable and may change in the future.
115+
*/
116+
#[Marshal(name: 'user_metadata')]
117+
public readonly UserMetadata $userMetadata;
118+
111119
private function __construct(WorkflowType $workflowType)
112120
{
113121
$this->workflowId = Uuid::v4();
@@ -122,6 +130,7 @@ private function __construct(WorkflowType $workflowType)
122130
$this->memo = EncodedCollection::empty();
123131
$this->searchAttributes = EncodedCollection::empty();
124132
$this->header = \Temporal\Interceptor\Header::empty();
133+
$this->userMetadata = new UserMetadata('', '');
125134
}
126135

127136
public static function new(string|WorkflowType $workflowType): self
@@ -267,6 +276,33 @@ public function withHeader(iterable|HeaderInterface $values): self
267276
return $this->with('header', $values);
268277
}
269278

279+
/**
280+
* Single-line fixed summary for this workflow execution that will appear in UI/CLI.
281+
*
282+
* This can be in single-line Temporal Markdown format.
283+
*
284+
* @experimental This feature is not stable and may change in the future.
285+
*/
286+
public function withStaticSummary(string $summary): self
287+
{
288+
/** @see self::$userMetadata */
289+
return $this->with('userMetadata', $this->userMetadata->withSummary($summary));
290+
}
291+
292+
/**
293+
* General fixed details for this workflow execution that will appear in UI/CLI.
294+
*
295+
* This can be in Temporal Markdown format and can span multiple lines. This is a fixed value on the workflow
296+
* that cannot be updated.
297+
*
298+
* @experimental This feature is not stable and may change in the future.
299+
*/
300+
public function withStaticDetails(string $details): self
301+
{
302+
/** @see self::$userMetadata */
303+
return $this->with('userMetadata', $this->userMetadata->withDetails($details));
304+
}
305+
270306
private static function createWorkflowType(string $name): WorkflowType
271307
{
272308
$workflowType = new WorkflowType();
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Temporal\Client\Workflow;
6+
7+
use Temporal\Internal\Marshaller\Meta\Marshal;
8+
use Temporal\Internal\Traits\CloneWith;
9+
10+
/**
11+
* Information a user can set, often for use by user interfaces.
12+
*
13+
* @see \Temporal\Api\Sdk\V1\UserMetadata
14+
*/
15+
final class UserMetadata
16+
{
17+
use CloneWith;
18+
19+
public function __construct(
20+
/**
21+
* Short-form text that provides a summary. This payload should be a "json/plain"-encoded payload
22+
* that is a single JSON string for use in user interfaces. User interface formatting may not
23+
* apply to this text when used in "title" situations. The payload data section is limited to 400
24+
* bytes by default.
25+
*/
26+
#[Marshal(name: 'summary')]
27+
public readonly string $summary,
28+
29+
/**
30+
* Long-form text that provides details. This payload should be a "json/plain"-encoded payload
31+
* that is a single JSON string for use in user interfaces. User interface formatting may apply to
32+
* this text in common use. The payload data section is limited to 20000 bytes by default.
33+
*/
34+
#[Marshal(name: 'details')]
35+
public readonly string $details,
36+
) {}
37+
38+
public function withSummary(string $summary): self
39+
{
40+
/** @see self::$summary */
41+
return $this->with('summary', $summary);
42+
}
43+
44+
public function withDetails(string $details): self
45+
{
46+
/** @see self::$details */
47+
return $this->with('details', $details);
48+
}
49+
}

src/Client/Workflow/WorkflowExecutionDescription.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Temporal\Client\Workflow;
66

7+
use Temporal\Workflow\WorkflowExecutionConfig;
78
use Temporal\Workflow\WorkflowExecutionInfo;
89

910
/**
@@ -19,6 +20,7 @@ final class WorkflowExecutionDescription
1920
* @internal
2021
*/
2122
public function __construct(
23+
public readonly WorkflowExecutionConfig $config,
2224
public readonly WorkflowExecutionInfo $info,
2325
) {}
2426
}

src/Client/WorkflowOptions.php

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,22 @@ final class WorkflowOptions extends Options
158158
*/
159159
public ?TypedSearchAttributes $typedSearchAttributes = null;
160160

161+
/**
162+
* General fixed details for this workflow execution that will appear in UI/CLI.
163+
*
164+
* @experimental This feature is not stable and may change in the future.
165+
*/
166+
#[Marshal(name: 'StaticDetails')]
167+
public string $staticDetails = '';
168+
169+
/**
170+
* Single-line fixed summary for this workflow execution that will appear in UI/CLI.
171+
*
172+
* @experimental This feature is not stable and may change in the future.
173+
*/
174+
#[Marshal(name: 'StaticSummary')]
175+
public string $staticSummary = '';
176+
161177
/**
162178
* @throws \Exception
163179
*/
@@ -446,6 +462,8 @@ public function withSearchAttributes(?array $searchAttributes): self
446462
*
447463
* The search attributes can be used in query of List/Scan/Count workflow APIs.
448464
* The key and its value type must be registered on Temporal server side.
465+
*
466+
* @return $this
449467
*/
450468
#[Pure]
451469
public function withTypedSearchAttributes(TypedSearchAttributes $attributes): self
@@ -459,12 +477,47 @@ public function withTypedSearchAttributes(TypedSearchAttributes $attributes): se
459477
return $self;
460478
}
461479

480+
/**
481+
* Single-line fixed summary for this workflow execution that will appear in UI/CLI.
482+
*
483+
* This can be in single-line Temporal Markdown format.
484+
*
485+
* @return $this
486+
* @since SDK 2.14.0
487+
* @experimental This API might change in the future.
488+
*/
489+
#[Pure]
490+
public function withStaticSummary(string $summary): self
491+
{
492+
$self = clone $this;
493+
$self->staticSummary = $summary;
494+
return $self;
495+
}
496+
497+
/**
498+
* General fixed details for this workflow execution that will appear in UI/CLI.
499+
*
500+
* This can be in Temporal Markdown format and can span multiple lines.
501+
* This is a fixed value on the workflow that cannot be updated.
502+
*
503+
* @return $this
504+
* @since SDK 2.14.0
505+
* @experimental This API might change in the future.
506+
*/
507+
#[Pure]
508+
public function withStaticDetails(string $details): self
509+
{
510+
$self = clone $this;
511+
$self->staticDetails = $details;
512+
return $self;
513+
}
514+
462515
/**
463516
* @internal
464517
*/
465518
public function toMemo(DataConverterInterface $converter): ?Memo
466519
{
467-
if ($this->memo === null) {
520+
if ($this->memo === null || $this->memo === []) {
468521
return null;
469522
}
470523

0 commit comments

Comments
 (0)