Skip to content

Commit

Permalink
Add UpsertTypedSearchAttributes command
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed Dec 30, 2024
1 parent 421d819 commit a0f79ea
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Common/SearchAttributes/SearchAttributeUpdate.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
abstract class SearchAttributeUpdate
{
/**
* @param non-empty-string $key
* @param non-empty-string $name
*/
protected function __construct(
public readonly string $key,
public readonly string $name,
public readonly ValueType $type,
) {}

Expand Down
50 changes: 50 additions & 0 deletions src/Internal/Transport/Request/UpsertTypedSearchAttributes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

declare(strict_types=1);

namespace Temporal\Internal\Transport\Request;

use Temporal\Common\SearchAttributes\SearchAttributeUpdate;
use Temporal\Common\SearchAttributes\SearchAttributeUpdate\ValueSet;
use Temporal\Worker\Transport\Command\Client\Request;

class UpsertTypedSearchAttributes extends Request
{
public const NAME = 'UpsertWorkflowTypedSearchAttributes';

/**
* @param list<SearchAttributeUpdate> $searchAttributes
*/
public function __construct(
private readonly array $searchAttributes,
) {
parent::__construct(self::NAME, ['searchAttributes' => $this->prepareSearchAttributes()]);
}

/**
* @return list<SearchAttributeUpdate>
*/
public function getSearchAttributes(): array
{
return $this->searchAttributes;
}

private function prepareSearchAttributes(): array {
$result = [];
foreach ($this->searchAttributes as $attr) {
$result[$attr->name] = $attr instanceof ValueSet
? [
'type' => $attr->type->value,
'operation' => 'set',
'value' => $attr->value,
]
: [
'type' => $attr->type->value,
'operation' => 'unset',
];
}

return $result;
}

}
9 changes: 9 additions & 0 deletions src/Internal/Workflow/ScopeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@

use React\Promise\Deferred;
use React\Promise\PromiseInterface;
use Temporal\Common\SearchAttributes\SearchAttributeUpdate;
use Temporal\Exception\Failure\CanceledFailure;
use Temporal\Internal\Transport\CompletableResult;
use Temporal\Internal\Transport\Request\UpsertTypedSearchAttributes;
use Temporal\Internal\Workflow\Process\Scope;
use Temporal\Worker\Transport\Command\RequestInterface;
use Temporal\Workflow\CancellationScopeInterface;
Expand Down Expand Up @@ -109,6 +111,13 @@ public function upsertSearchAttributes(array $searchAttributes): void
);
}

public function upsertTypedSearchAttributes(SearchAttributeUpdate ...$updates): void
{
$this->request(
new UpsertTypedSearchAttributes($updates),
);
}

#[\Override]
public function destroy(): void
{
Expand Down

0 comments on commit a0f79ea

Please sign in to comment.