Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add default implementation for upsertMemo method in interceptors #569

Merged
merged 5 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Temporal\Interceptor\WorkflowOutboundCalls\SideEffectInput;
use Temporal\Interceptor\WorkflowOutboundCalls\SignalExternalWorkflowInput;
use Temporal\Interceptor\WorkflowOutboundCalls\TimerInput;
use Temporal\Interceptor\WorkflowOutboundCalls\UpsertMemoInput;
use Temporal\Interceptor\WorkflowOutboundCalls\UpsertSearchAttributesInput;
use Temporal\Interceptor\WorkflowOutboundCalls\UpsertTypedSearchAttributesInput;
use Temporal\Interceptor\WorkflowOutboundCallsInterceptor;
Expand Down Expand Up @@ -148,6 +149,14 @@ public function getVersion(GetVersionInput $input, callable $next): PromiseInter
return $next($input);
}

/**
* @param callable(UpsertMemoInput): PromiseInterface $next
*/
public function upsertMemo(UpsertMemoInput $input, callable $next): PromiseInterface
{
return $next($input);
}

/**
* Default implementation of the `upsertSearchAttributes` method.
*
Expand Down
35 changes: 18 additions & 17 deletions src/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -912,34 +912,35 @@ public static function allHandlersFinished(): bool
* For example:
*
* ```php
* Workflow::upsertMemo([
* 'key1' => 'value',
* 'key3' => ['subkey1' => 'value']
* 'key4' => 'value',
* });
*
* Workflow::upsertMemo([
* 'key2' => 'value',
* 'key3' => ['subkey2' => 'value']
* 'key4' => null,
* ]);
* Workflow::upsertMemo([
* 'key1' => 'value',
* 'key3' => ['subkey1' => 'value']
* 'key4' => 'value',
* });
*
* Workflow::upsertMemo([
* 'key2' => 'value',
* 'key3' => ['subkey2' => 'value']
* 'key4' => null,
* ]);
* ```
*
* would result in the Workflow having these Memo:
*
* ```php
* [
* 'key1' => 'value',
* 'key2' => 'value',
* 'key3' => ['subkey2' => 'value'], // Note this object was completely replaced
* // Note that 'key4' was completely removed
* ]
* [
* 'key1' => 'value',
* 'key2' => 'value',
* 'key3' => ['subkey2' => 'value'], // Note this object was completely replaced
* // Note that 'key4' was completely removed
* ]
* ```
*
* @param array<non-empty-string, mixed> $values
*
* @since SDK 2.13.0
* @since RoadRunner 2024.3.3
* @link https://docs.temporal.io/glossary#memo
*/
public static function upsertMemo(array $values): void
{
Expand Down
5 changes: 5 additions & 0 deletions tests/Acceptance/App/Runtime/RRStarter.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,9 @@ public function stop(): void
$this->environment->stop();
$this->started = false;
}

public function __destruct()
{
$this->stop();
}
}
2 changes: 0 additions & 2 deletions tests/Acceptance/Extra/Workflow/MemoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,6 @@ public function handle()
fn(): bool => $this->exit,
);

tr(Workflow::getInfo()->memo);

return Workflow::getInfo()->memo;
}

Expand Down
Loading