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
1 change: 1 addition & 0 deletions src/Activity/ActivityCancellationDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public function __construct(
public readonly bool $paused = false,
public readonly bool $timedOut = false,
public readonly bool $workerShutdown = false,
public readonly bool $reset = false,
) {}
}
2 changes: 2 additions & 0 deletions src/Activity/ActivityContextInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Temporal\Exception\Client\ActivityCanceledException;
use Temporal\Exception\Client\ActivityCompletionException;
use Temporal\Exception\Client\ActivityPausedException;
use Temporal\Exception\Client\ActivityResetException;

interface ActivityContextInterface
{
Expand Down Expand Up @@ -63,6 +64,7 @@ public function doNotCompleteOnReturn(): void;
* @throws ActivityCompletionException
* @throws ActivityCanceledException
* @throws ActivityPausedException
* @throws ActivityResetException
*
* @see Activity::heartbeat()
*
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/Client/ActivityPausedException.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
* Indicates that the activity was paused by the user.
*
* Catching this exception directly is discouraged and catching
* the parent class {@link ActivityCompletionException} is recommended instead.
* the parent class {@see ActivityCompletionException} is recommended instead.
*/
final class ActivityPausedException extends ActivityCompletionException {}
20 changes: 20 additions & 0 deletions src/Exception/Client/ActivityResetException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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;

/**
* Indicates that the activity attempt was reset by the user.
*
* Catching this exception directly is discouraged and catching
* the parent class {@see ActivityCompletionException} is recommended instead.
*/
final class ActivityResetException extends ActivityCompletionException {}
13 changes: 9 additions & 4 deletions src/Internal/Activity/ActivityContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Temporal\Exception\Client\ActivityCanceledException;
use Temporal\Exception\Client\ActivityCompletionException;
use Temporal\Exception\Client\ActivityPausedException;
use Temporal\Exception\Client\ActivityResetException;
use Temporal\Exception\Client\ServiceClientException;
use Temporal\Interceptor\HeaderInterface;
use Temporal\Internal\Interceptor\HeaderCarrier;
Expand Down Expand Up @@ -129,16 +130,20 @@ public function heartbeat(mixed $details): void

$cancelled = (bool) ($response['canceled'] ?? false);
$paused = (bool) ($response['paused'] ?? false);
$reset = (bool) ($response['reset'] ?? false);

if ($cancelled || $paused) {
if ($cancelled || $paused || $reset) {
$this->cancellationDetails ??= new ActivityCancellationDetails(
cancelRequested: $cancelled,
paused: $paused,
reset: $reset,
);

throw $cancelled
? ActivityCanceledException::fromActivityInfo($this->info)
: ActivityPausedException::fromActivityInfo($this->info);
throw match (true) {
$cancelled => ActivityCanceledException::fromActivityInfo($this->info),
$paused => ActivityPausedException::fromActivityInfo($this->info),
$reset => ActivityResetException::fromActivityInfo($this->info),
};
}
} catch (ServiceClientException $e) {
throw ActivityCompletionException::fromActivityInfo($this->info, $e);
Expand Down
Loading