Skip to content

Commit e102382

Browse files
committed
feat: Throw ActivityResetException on Activity reset
1 parent 8358594 commit e102382

File tree

5 files changed

+33
-5
lines changed

5 files changed

+33
-5
lines changed

src/Activity/ActivityCancellationDetails.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ public function __construct(
1818
public readonly bool $paused = false,
1919
public readonly bool $timedOut = false,
2020
public readonly bool $workerShutdown = false,
21+
public readonly bool $reset = false,
2122
) {}
2223
}

src/Activity/ActivityContextInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Temporal\Exception\Client\ActivityCanceledException;
1818
use Temporal\Exception\Client\ActivityCompletionException;
1919
use Temporal\Exception\Client\ActivityPausedException;
20+
use Temporal\Exception\Client\ActivityResetException;
2021

2122
interface ActivityContextInterface
2223
{
@@ -63,6 +64,7 @@ public function doNotCompleteOnReturn(): void;
6364
* @throws ActivityCompletionException
6465
* @throws ActivityCanceledException
6566
* @throws ActivityPausedException
67+
* @throws ActivityResetException
6668
*
6769
* @see Activity::heartbeat()
6870
*

src/Exception/Client/ActivityPausedException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
* Indicates that the activity was paused by the user.
1616
*
1717
* Catching this exception directly is discouraged and catching
18-
* the parent class {@link ActivityCompletionException} is recommended instead.
18+
* the parent class {@see ActivityCompletionException} is recommended instead.
1919
*/
2020
final class ActivityPausedException extends ActivityCompletionException {}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
/**
4+
* This file is part of Temporal package.
5+
*
6+
* For the full copyright and license information, please view the LICENSE
7+
* file that was distributed with this source code.
8+
*/
9+
10+
declare(strict_types=1);
11+
12+
namespace Temporal\Exception\Client;
13+
14+
/**
15+
* Indicates that the activity attempt was reset by the user.
16+
*
17+
* Catching this exception directly is discouraged and catching
18+
* the parent class {@see ActivityCompletionException} is recommended instead.
19+
*/
20+
final class ActivityResetException extends ActivityCompletionException {}

src/Internal/Activity/ActivityContext.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Temporal\Exception\Client\ActivityCanceledException;
2222
use Temporal\Exception\Client\ActivityCompletionException;
2323
use Temporal\Exception\Client\ActivityPausedException;
24+
use Temporal\Exception\Client\ActivityResetException;
2425
use Temporal\Exception\Client\ServiceClientException;
2526
use Temporal\Interceptor\HeaderInterface;
2627
use Temporal\Internal\Interceptor\HeaderCarrier;
@@ -129,16 +130,20 @@ public function heartbeat(mixed $details): void
129130

130131
$cancelled = (bool) ($response['canceled'] ?? false);
131132
$paused = (bool) ($response['paused'] ?? false);
133+
$reset = (bool) ($response['reset'] ?? false);
132134

133-
if ($cancelled || $paused) {
135+
if ($cancelled || $paused || $reset) {
134136
$this->cancellationDetails ??= new ActivityCancellationDetails(
135137
cancelRequested: $cancelled,
136138
paused: $paused,
139+
reset: $reset,
137140
);
138141

139-
throw $cancelled
140-
? ActivityCanceledException::fromActivityInfo($this->info)
141-
: ActivityPausedException::fromActivityInfo($this->info);
142+
throw match (true) {
143+
$cancelled => ActivityCanceledException::fromActivityInfo($this->info),
144+
$paused => ActivityPausedException::fromActivityInfo($this->info),
145+
$reset => ActivityResetException::fromActivityInfo($this->info),
146+
};
142147
}
143148
} catch (ServiceClientException $e) {
144149
throw ActivityCompletionException::fromActivityInfo($this->info, $e);

0 commit comments

Comments
 (0)