Skip to content

Commit

Permalink
Move WorkflowExecutionHistory into another namespace; expose an abi…
Browse files Browse the repository at this point in the history
…lity to describe a Workflow
  • Loading branch information
roxblnfk committed Apr 9, 2024
1 parent c13912c commit 2c4bf07
Show file tree
Hide file tree
Showing 10 changed files with 123 additions and 1 deletion.
22 changes: 22 additions & 0 deletions src/Client/Workflow/WorkflowExecutionDescription.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Temporal\Client\Workflow;

use Temporal\Workflow\WorkflowExecutionInfo;

/**
* DTO that contains detailed information about Workflow Execution.
*
* @see \Temporal\Api\Workflowservice\V1\DescribeWorkflowExecutionResponse
*
* @internal
*/
final class WorkflowExecutionDescription
{
public function __construct(
public readonly WorkflowExecutionInfo $info,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Temporal\Client;
namespace Temporal\Client\Workflow;

use Generator;
use IteratorAggregate;
Expand Down
1 change: 1 addition & 0 deletions src/Client/WorkflowClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
use Temporal\Client\Common\Paginator;
use Temporal\Client\GRPC\ServiceClientInterface;
use Temporal\Client\Workflow\CountWorkflowExecutions;
use Temporal\Client\Workflow\WorkflowExecutionHistory;
use Temporal\DataConverter\DataConverter;
use Temporal\DataConverter\DataConverterInterface;
use Temporal\DataConverter\Type;
Expand Down
1 change: 1 addition & 0 deletions src/Client/WorkflowClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Temporal\Client\Common\Paginator;
use Temporal\Client\GRPC\ServiceClientInterface;
use Temporal\Client\Workflow\CountWorkflowExecutions;
use Temporal\Client\Workflow\WorkflowExecutionHistory;
use Temporal\Workflow\WorkflowExecution;
use Temporal\Workflow\WorkflowExecutionInfo as WorkflowExecutionInfoDto;
use Temporal\Workflow\WorkflowRunInterface;
Expand Down
12 changes: 12 additions & 0 deletions src/Interceptor/Trait/WorkflowClientCallsInterceptorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@

namespace Temporal\Interceptor\Trait;

use Temporal\Client\Workflow\WorkflowExecutionDescription;
use Temporal\DataConverter\EncodedValues;
use Temporal\Interceptor\WorkflowClient\CancelInput;
use Temporal\Interceptor\WorkflowClient\DescribeInput;
use Temporal\Interceptor\WorkflowClient\GetResultInput;
use Temporal\Interceptor\WorkflowClient\QueryInput;
use Temporal\Interceptor\WorkflowClient\SignalInput;
Expand Down Expand Up @@ -110,4 +112,14 @@ public function terminate(TerminateInput $input, callable $next): void
{
$next($input);
}

/**
* Default implementation of the `describe` method.
*
* @see WorkflowClientCallsInterceptor::describe()
*/
public function describe(DescribeInput $input, callable $next): WorkflowExecutionDescription
{
return $next($input);
}
}
38 changes: 38 additions & 0 deletions src/Interceptor/WorkflowClient/DescribeInput.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

/**
* This file is part of Temporal package.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Temporal\Interceptor\WorkflowClient;

use Temporal\Workflow\WorkflowExecution;

/**
* @psalm-immutable
*/
class DescribeInput
{
/**
* @no-named-arguments
* @internal Don't use the constructor. Use {@see self::with()} instead.
*/
public function __construct(
public readonly WorkflowExecution $workflowExecution,
public readonly string $namespace,
) {
}

public function with(
WorkflowExecution $workflowExecution = null,
string $namespace = null,
): self {
return new self(
$workflowExecution ?? $this->workflowExecution,
$namespace ?? $this->namespace,
);
}
}
10 changes: 10 additions & 0 deletions src/Interceptor/WorkflowClientCallsInterceptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@

namespace Temporal\Interceptor;

use Temporal\Client\Workflow\WorkflowExecutionDescription;
use Temporal\DataConverter\ValuesInterface;
use Temporal\Interceptor\Trait\WorkflowClientCallsInterceptorTrait;
use Temporal\Interceptor\WorkflowClient\CancelInput;
use Temporal\Interceptor\WorkflowClient\DescribeInput;
use Temporal\Interceptor\WorkflowClient\GetResultInput;
use Temporal\Interceptor\WorkflowClient\QueryInput;
use Temporal\Interceptor\WorkflowClient\SignalInput;
Expand Down Expand Up @@ -110,4 +112,12 @@ public function cancel(CancelInput $input, callable $next): void;
* @return void
*/
public function terminate(TerminateInput $input, callable $next): void;

/**
* @param DescribeInput $input
* @param callable(DescribeInput): void $next
*
* @return WorkflowExecutionDescription
*/
public function describe(DescribeInput $input, callable $next): WorkflowExecutionDescription;
}
6 changes: 6 additions & 0 deletions src/Internal/Client/WorkflowRun.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Temporal\Internal\Client;

use Temporal\Client\Workflow\WorkflowExecutionDescription;
use Temporal\Client\WorkflowStubInterface;
use Temporal\DataConverter\Type;
use Temporal\Workflow\WorkflowExecution;
Expand Down Expand Up @@ -43,4 +44,9 @@ public function getResult($type = null, int $timeout = null): mixed
{
return $this->stub->getResult($type ?? $this->returnType, $timeout);
}

public function describe(): WorkflowExecutionDescription
{
return $this->stub->describe();
}
}
29 changes: 29 additions & 0 deletions src/Internal/Client/WorkflowStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Temporal\Api\History\V1\HistoryEvent;
use Temporal\Api\Query\V1\WorkflowQuery;
use Temporal\Api\Update\V1\Request as UpdateRequestMessage;
use Temporal\Api\Workflowservice\V1\DescribeWorkflowExecutionRequest;
use Temporal\Api\Workflowservice\V1\GetWorkflowExecutionHistoryRequest;
use Temporal\Api\Workflowservice\V1\QueryWorkflowRequest;
use Temporal\Api\Workflowservice\V1\RequestCancelWorkflowExecutionRequest;
Expand All @@ -34,6 +35,7 @@
use Temporal\Client\Update\UpdateHandle;
use Temporal\Client\Update\UpdateOptions;
use Temporal\Client\Update\WaitPolicy;
use Temporal\Client\Workflow\WorkflowExecutionDescription;
use Temporal\Client\WorkflowOptions;
use Temporal\Client\WorkflowStubInterface;
use Temporal\Common\Uuid;
Expand All @@ -58,6 +60,7 @@
use Temporal\Interceptor\Header;
use Temporal\Interceptor\HeaderInterface;
use Temporal\Interceptor\WorkflowClient\CancelInput;
use Temporal\Interceptor\WorkflowClient\DescribeInput;
use Temporal\Interceptor\WorkflowClient\GetResultInput;
use Temporal\Interceptor\WorkflowClient\QueryInput;
use Temporal\Interceptor\WorkflowClient\SignalInput;
Expand All @@ -68,6 +71,7 @@
use Temporal\Interceptor\WorkflowClientCallsInterceptor;
use Temporal\Internal\Interceptor\HeaderCarrier;
use Temporal\Internal\Interceptor\Pipeline;
use Temporal\Internal\Mapper\WorkflowExecutionInfoMapper;
use Temporal\Workflow\WorkflowExecution;

final class WorkflowStub implements WorkflowStubInterface, HeaderCarrier
Expand Down Expand Up @@ -496,6 +500,31 @@ function (GetResultInput $input): ?EncodedValues {
return $result->getValue(0, $type);
}

public function describe(): WorkflowExecutionDescription
{
$this->assertStarted(__FUNCTION__);

return $this->interceptors->with(
function (DescribeInput $input): WorkflowExecutionDescription {
$request = new DescribeWorkflowExecutionRequest();
$request->setNamespace($input->namespace);
$request->setExecution($input->workflowExecution->toProtoWorkflowExecution());

$response = $this->serviceClient->DescribeWorkflowExecution($request);
$mapper = new WorkflowExecutionInfoMapper($this->converter);

return new WorkflowExecutionDescription(
info: $mapper->fromMessage($response->getWorkflowExecutionInfo()),

Check failure on line 517 in src/Internal/Client/WorkflowStub.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)

PossiblyNullArgument

src/Internal/Client/WorkflowStub.php:517:48: PossiblyNullArgument: Argument 1 of Temporal\Internal\Mapper\WorkflowExecutionInfoMapper::fromMessage cannot be null, possibly null value provided (see https://psalm.dev/078)

Check failure on line 517 in src/Internal/Client/WorkflowStub.php

View workflow job for this annotation

GitHub Actions / Psalm Validation (PHP 8.3, OS ubuntu-latest)

PossiblyNullArgument

src/Internal/Client/WorkflowStub.php:517:48: PossiblyNullArgument: Argument 1 of Temporal\Internal\Mapper\WorkflowExecutionInfoMapper::fromMessage cannot be null, possibly null value provided (see https://psalm.dev/078)
);
},
/** @see WorkflowClientCallsInterceptor::describe() */
'describe',
)(new DescribeInput(
$this->execution,
$this->clientOptions->namespace,
));
}

/**
* @param string $method
* @psalm-assert !null $this->execution
Expand Down
3 changes: 3 additions & 0 deletions src/Workflow/WorkflowRunInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Temporal\Workflow;

use Temporal\Client\Workflow\WorkflowExecutionDescription;
use Temporal\DataConverter\Type;
use Temporal\Exception\Client\WorkflowFailedException;

Expand Down Expand Up @@ -47,4 +48,6 @@ public function getExecution(): WorkflowExecution;
* @see DateInterval
*/
public function getResult($type = null, int $timeout = null): mixed;

public function describe(): WorkflowExecutionDescription;
}

0 comments on commit 2c4bf07

Please sign in to comment.