Skip to content
Draft
Show file tree
Hide file tree
Changes from all 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
26 changes: 26 additions & 0 deletions src/Activity/LocalActivityOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down Expand Up @@ -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;
}
}
55 changes: 55 additions & 0 deletions tests/Acceptance/Extra/Workflow/UserMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
{
Expand All @@ -254,3 +300,12 @@ public function execute(): string
return 'done';
}
}

#[ActivityInterface('Extra_Workflow_UserMetadata.Local.')]
class TestLocalActivity
{
public function execute(): string
{
return 'done';
}
}
Loading