Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WorkflowUpdateResultException #526

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
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
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;
}
}
Loading