diff --git a/src/Activity/LocalActivityOptions.php b/src/Activity/LocalActivityOptions.php index 4099b1bd..d8d896ea 100644 --- a/src/Activity/LocalActivityOptions.php +++ b/src/Activity/LocalActivityOptions.php @@ -67,6 +67,14 @@ class LocalActivityOptions extends Options implements ActivityOptionsInterface #[Marshal(name: 'RetryPolicy', type: NullableType::class, of: RetryOptions::class)] public ?RetryOptions $retryOptions = null; + /** + * Optional summary of the activity. + * + * @experimental This API is experimental and may change in the future. + */ + #[Marshal(name: 'Summary')] + public string $summary = ''; + /** * ActivityOptions constructor. */ @@ -152,4 +160,22 @@ public function withRetryOptions(?RetryOptions $options): self return $self; } + + /** + * Optional summary of the activity. + * + * Single-line fixed summary for this activity that will appear in UI/CLI. + * This can be in single-line Temporal Markdown format. + * + * @experimental This API is experimental and may change in the future. + * + * @return $this + */ + #[Pure] + public function withSummary(string $summary): self + { + $self = clone $this; + $self->summary = $summary; + return $self; + } } diff --git a/tests/Acceptance/Extra/Workflow/UserMetadataTest.php b/tests/Acceptance/Extra/Workflow/UserMetadataTest.php index 87c165db..3d847854 100644 --- a/tests/Acceptance/Extra/Workflow/UserMetadataTest.php +++ b/tests/Acceptance/Extra/Workflow/UserMetadataTest.php @@ -7,6 +7,7 @@ use PHPUnit\Framework\Attributes\Test; use Temporal\Activity\ActivityInterface; use Temporal\Activity\ActivityOptions; +use Temporal\Activity\LocalActivityOptions; use Temporal\Api\Common\V1\Payload; use Temporal\Client\Schedule\Action\StartWorkflowAction; use Temporal\Client\Schedule\Schedule; @@ -185,6 +186,39 @@ public function activityMetadata( } } + #[Test] + public function localActivityMetadata( + #[Stub('Extra_Workflow_UserMetadata')] + WorkflowStubInterface $stub, + WorkflowClientInterface $client, + DataConverterInterface $dataConverter, + ): void { + try { + /** @see TestWorkflow::executeLocalActivity() */ + $fromActivity = (string) $stub + ->update('execute_local_activity', 'test local activity summary') + ->getValue(0); + self::assertSame('done', $fromActivity); + + # Check that the local activity was executed and metadata was set + $found = false; + foreach ($client->getWorkflowHistory($stub->getExecution()) as $event) { + if ($event->hasMarkerRecordedEventAttributes()) { + $payload = $event->getUserMetadata()?->getSummary(); + self::assertInstanceOf(Payload::class, $payload); + $data = $dataConverter->fromPayload($payload, 'string'); + self::assertSame('test local activity summary', $data); + $found = true; + break; + } + } + + self::assertTrue($found, 'Activity metadata not found in workflow history'); + } finally { + self::terminate($stub); + } + } + private static function terminate(WorkflowStubInterface $stub): void { try { @@ -239,6 +273,18 @@ public function executeActivity(string $summary) ); } + #[Workflow\UpdateMethod('execute_local_activity')] + public function executeLocalActivity(string $summary) + { + /** @see TestActivity::execute() */ + return yield Workflow::executeActivity( + 'Extra_Workflow_UserMetadata.Local.execute', + options: LocalActivityOptions::new() + ->withScheduleToCloseTimeout(30) + ->withSummary($summary), + ); + } + #[Workflow\SignalMethod] public function exit(): void { @@ -254,3 +300,12 @@ public function execute(): string return 'done'; } } + +#[ActivityInterface('Extra_Workflow_UserMetadata.Local.')] +class TestLocalActivity +{ + public function execute(): string + { + return 'done'; + } +}