Skip to content

Commit f5e6323

Browse files
committed
Add UpsertTypedSearchAttributes command
1 parent 421d819 commit f5e6323

File tree

3 files changed

+61
-2
lines changed

3 files changed

+61
-2
lines changed

src/Common/SearchAttributes/SearchAttributeUpdate.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
abstract class SearchAttributeUpdate
1515
{
1616
/**
17-
* @param non-empty-string $key
17+
* @param non-empty-string $name
1818
*/
1919
protected function __construct(
20-
public readonly string $key,
20+
public readonly string $name,
2121
public readonly ValueType $type,
2222
) {}
2323

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Temporal\Internal\Transport\Request;
6+
7+
use Temporal\Common\SearchAttributes\SearchAttributeUpdate;
8+
use Temporal\Common\SearchAttributes\SearchAttributeUpdate\ValueSet;
9+
use Temporal\Worker\Transport\Command\Client\Request;
10+
11+
class UpsertTypedSearchAttributes extends Request
12+
{
13+
public const NAME = 'UpsertWorkflowTypedSearchAttributes';
14+
15+
/**
16+
* @param list<SearchAttributeUpdate> $searchAttributes
17+
*/
18+
public function __construct(
19+
private readonly array $searchAttributes,
20+
) {
21+
parent::__construct(self::NAME, ['searchAttributes' => $this->prepareSearchAttributes()]);
22+
}
23+
24+
/**
25+
* @return list<SearchAttributeUpdate>
26+
*/
27+
public function getSearchAttributes(): array
28+
{
29+
return $this->searchAttributes;
30+
}
31+
32+
private function prepareSearchAttributes(): array
33+
{
34+
$result = [];
35+
foreach ($this->searchAttributes as $attr) {
36+
$result[$attr->name] = $attr instanceof ValueSet
37+
? [
38+
'type' => $attr->type->value,
39+
'operation' => 'set',
40+
'value' => $attr->value,
41+
]
42+
: [
43+
'type' => $attr->type->value,
44+
'operation' => 'unset',
45+
];
46+
}
47+
48+
return $result;
49+
}
50+
}

src/Internal/Workflow/ScopeContext.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313

1414
use React\Promise\Deferred;
1515
use React\Promise\PromiseInterface;
16+
use Temporal\Common\SearchAttributes\SearchAttributeUpdate;
1617
use Temporal\Exception\Failure\CanceledFailure;
1718
use Temporal\Internal\Transport\CompletableResult;
19+
use Temporal\Internal\Transport\Request\UpsertTypedSearchAttributes;
1820
use Temporal\Internal\Workflow\Process\Scope;
1921
use Temporal\Worker\Transport\Command\RequestInterface;
2022
use Temporal\Workflow\CancellationScopeInterface;
@@ -109,6 +111,13 @@ public function upsertSearchAttributes(array $searchAttributes): void
109111
);
110112
}
111113

114+
public function upsertTypedSearchAttributes(SearchAttributeUpdate ...$updates): void
115+
{
116+
$this->request(
117+
new UpsertTypedSearchAttributes($updates),
118+
);
119+
}
120+
112121
#[\Override]
113122
public function destroy(): void
114123
{

0 commit comments

Comments
 (0)