Skip to content
Merged
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
1 change: 1 addition & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,7 @@
<code><![CDATA[$scope]]></code>
</PropertyNotSetInConstructor>
<UnsupportedPropertyReferenceUsage>
<code><![CDATA[$ctx->currentDetails = &$context->currentDetails]]></code>
<code><![CDATA[$ctx->trace = &$context->trace]]></code>
</UnsupportedPropertyReferenceUsage>
</file>
Expand Down
8 changes: 7 additions & 1 deletion src/DataConverter/ProtoJsonConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ public function toPayload($value): ?Payload
public function fromPayload(Payload $payload, Type $type)
{
if (!$type->isClass()) {
throw new DataConverterException('Unable to decode value using protobuf converter - ');
throw new DataConverterException(
\sprintf(
'Unable to decode value using "%s" encoding converter: resulting type must be a class, "%s" given',
$this->getEncodingType(),
$type->getName(),
),
);
}

try {
Expand Down
14 changes: 8 additions & 6 deletions src/Internal/Transport/Router/InvokeQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,14 @@ private function workflowMetadata(Deferred $resolver, WorkflowContext $context):
static function () use ($resolver, $context): void {
try {
$result = EncodedValues::fromValues([
(new WorkflowMetadata())->setDefinition(
(new WorkflowDefinition())
->setQueryDefinitions($context->getQueryDispatcher()->getQueryHandlers())
->setSignalDefinitions($context->getSignalDispatcher()->getSignalHandlers())
->setUpdateDefinitions($context->getUpdateDispatcher()->getUpdateHandlers()),
),
(new WorkflowMetadata())
->setDefinition(
(new WorkflowDefinition())
->setQueryDefinitions($context->getQueryDispatcher()->getQueryHandlers())
->setSignalDefinitions($context->getSignalDispatcher()->getSignalHandlers())
->setUpdateDefinitions($context->getUpdateDispatcher()->getUpdateHandlers()),
)
->setCurrentDetails((string) $context->getCurrentDetails()),
]);

$resolver->resolve($result);
Expand Down
1 change: 1 addition & 0 deletions src/Internal/Workflow/ScopeContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public static function fromWorkflowContext(
$ctx->readonly = $context->readonly;
$ctx->continueAsNew = $context->continueAsNew;
$ctx->trace = &$context->trace;
$ctx->currentDetails = &$context->currentDetails;

return $ctx;
}
Expand Down
17 changes: 17 additions & 0 deletions src/Internal/Workflow/WorkflowContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class WorkflowContext implements WorkflowContextInterface, HeaderCarrier, Destro
protected array $trace = [];
protected bool $continueAsNew = false;
protected bool $readonly = true;
protected ?string $currentDetails = null;

/** @var Pipeline<WorkflowOutboundRequestInterceptor, PromiseInterface> */
private Pipeline $requestInterceptor;
Expand Down Expand Up @@ -723,6 +724,22 @@ public function getUpdateDispatcher(): UpdateDispatcher
return $this->updateDispatcher;
}

/**
* Get the current details of the workflow execution.
*/
public function getCurrentDetails(): ?string
{
return $this->currentDetails;
}

/**
* Set the current details of the workflow execution.
*/
public function setCurrentDetails(?string $details): void
{
$this->currentDetails = $details;
}

protected function awaitRequest(callable|Mutex|PromiseInterface ...$conditions): PromiseInterface
{
$result = [];
Expand Down
16 changes: 16 additions & 0 deletions src/Workflow.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,22 @@ public static function timer($interval, ?TimerOptions $options = null): PromiseI
return self::getCurrentContext()->timer($interval, $options);
}

/**
* Get the current details of the workflow execution.
*/
public static function getCurrentDetails(): ?string
{
return self::getCurrentContext()->getCurrentDetails();
}

/**
* Set the current details of the workflow execution.
*/
public static function setCurrentDetails(?string $details): void
{
self::getCurrentContext()->setCurrentDetails($details);
}

/**
* Completes the current workflow execution atomically and starts a new execution with the same Workflow Id.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Workflow/WorkflowContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,14 @@ public function getLogger(): LoggerInterface;
* Get the currently running Workflow instance.
*/
public function getInstance(): object;

/**
* Get the current details of the workflow execution.
*/
public function getCurrentDetails(): ?string;

/**
* Set the current details of the workflow execution.
*/
public function setCurrentDetails(?string $details): void;
}
60 changes: 60 additions & 0 deletions tests/Acceptance/Extra/Workflow/WorkflowMetadataTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace Temporal\Tests\Acceptance\Extra\Workflow\WorkflowMetadata;

use PHPUnit\Framework\Attributes\Test;
use Temporal\Api\Sdk\V1\WorkflowMetadata;
use Temporal\Client\WorkflowStubInterface;
use Temporal\Tests\Acceptance\App\Attribute\Stub;
use Temporal\Tests\Acceptance\App\TestCase;
use Temporal\Workflow;
use Temporal\Workflow\WorkflowInterface;
use Temporal\Workflow\WorkflowMethod;

class WorkflowMetadataTest extends TestCase
{
#[Test]
public function metadataQuery(
#[Stub('Extra_Workflow_WorkflowMetadata', args: ["from test"])] WorkflowStubInterface $stub,
): void {
$values = $stub->query('__temporal_workflow_metadata');
/**
* @var WorkflowMetadata|null $metadata
*/
$metadata = $values->getValue(0, WorkflowMetadata::class);

$stub->signal('exit');
$this->assertSame("Cooking workflow from test", $metadata->getCurrentDetails());
}
}

#[WorkflowInterface]
class TestWorkflow
{
private bool $exit = false;

#[WorkflowMethod(name: "Extra_Workflow_WorkflowMetadata")]
public function handle(string $payload)
{
Workflow::setCurrentDetails("Cooking workflow " . $payload);

yield Workflow::await(fn() => $this->exit);
}

/**
* @return null|non-empty-string
*/
#[Workflow\QueryMethod]
public function getCurrentDetails(): ?string
{
return Workflow::getCurrentDetails();
}

#[Workflow\SignalMethod]
public function exit(): void
{
$this->exit = true;
}
}
Loading