Skip to content

Commit

Permalink
Throw WorkflowUpdateResultException when an update result was not pro…
Browse files Browse the repository at this point in the history
…vided
  • Loading branch information
roxblnfk committed Nov 13, 2024
1 parent a1a6c59 commit d4a2eaf
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/Client/Update/UpdateHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Temporal\Exception\Client\CanceledException;
use Temporal\Exception\Client\TimeoutException;
use Temporal\Exception\Client\WorkflowUpdateException;
use Temporal\Exception\Client\WorkflowUpdateResultException;
use Temporal\Exception\Client\WorkflowUpdateRPCTimeoutOrCanceledException;
use Temporal\Exception\Failure\FailureConverter;
use Temporal\Workflow\WorkflowExecution;
Expand Down Expand Up @@ -127,7 +128,13 @@ private function fetchResult(int|float|null $timeout = null): void

// Workflow Uprate accepted
$result = $response->getOutcome();
\assert($result !== null);
$result === null and throw new WorkflowUpdateResultException(
LifecycleStage::tryFrom($response->getStage()),
execution: $this->getExecution(),
workflowType: $this->workflowType ?? '',
updateId: $this->getId(),
updateName: $this->updateName,
);

// Accepted with result
if ($result->getSuccess() !== null) {
Expand Down
55 changes: 55 additions & 0 deletions src/Exception/Client/WorkflowUpdateResultException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?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.
*/

declare(strict_types=1);

namespace Temporal\Exception\Client;

use Temporal\Client\Update\LifecycleStage;
use Temporal\Workflow\WorkflowExecution;

/**
* Indicates that a Workflow Update has no result yet.
*/
final class WorkflowUpdateResultException extends WorkflowException
{
public function __construct(
private readonly ?LifecycleStage $stage,
WorkflowExecution $execution,
string $workflowType,
private readonly string $updateId,
private readonly string $updateName,
) {
$message = match ($stage) {
LifecycleStage::StageAdmitted => \sprintf(
"Update `%s` has not yet been accepted or rejected by the Workflow `%s`.",
$updateName,
$workflowType,
),
default => \sprintf("Update `%s` has no result.", $updateName),
};

parent::__construct($message, $execution, $workflowType);
}

public function getUpdateId(): string
{
return $this->updateId;
}

public function getUpdateName(): string
{
return $this->updateName;
}

public function getStage(): LifecycleStage
{
return $this->stage ?? LifecycleStage::StageUnspecified;
}
}

0 comments on commit d4a2eaf

Please sign in to comment.