Skip to content

Commit 168cc99

Browse files
authored
Merge pull request #591: Continuous polling in UpdateHandle::fetchResult() until deadline
2 parents 2c7b2ed + 51ac9e4 commit 168cc99

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

psalm-baseline.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@
135135
<code><![CDATA[$options->namespace]]></code>
136136
</DeprecatedProperty>
137137
</file>
138-
<file src="src/Client/Update/UpdateHandle.php">
139-
<PossiblyNullArgument>
140-
<code><![CDATA[$result->getSuccess()]]></code>
141-
</PossiblyNullArgument>
142-
</file>
143138
<file src="src/Client/WorkflowClient.php">
144139
<ArgumentTypeCoercion>
145140
<code><![CDATA[$counter]]></code>

src/Client/Update/UpdateHandle.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -114,22 +114,38 @@ private function fetchResult(int|float|null $timeout = null): void
114114
(new \Temporal\Api\Update\V1\WaitPolicy())->setLifecycleStage(LifecycleStage::StageCompleted->value),
115115
);
116116

117-
try {
118-
$response = $this->client->PollWorkflowExecutionUpdate(
119-
$request,
120-
$timeout === null ? null : $this->client->getContext()->withTimeout($timeout),
121-
);
122-
} catch (TimeoutException|CanceledException $e) {
123-
throw WorkflowUpdateRPCTimeoutOrCanceledException::fromTimeoutOrCanceledException($e);
124-
}
125117

126-
// Workflow Uprate accepted
127-
$result = $response->getOutcome();
128-
\assert($result !== null);
118+
$context = $timeout === null
119+
? $this->client->getContext()
120+
: $this->client->getContext()->withTimeout($timeout);
121+
$deadline = $context->getDeadline();
122+
123+
// Convert request timeout into deadline
124+
$deadline === null or $context = $context->withDeadline($deadline);
125+
126+
do {
127+
try {
128+
$response = $this->client->PollWorkflowExecutionUpdate($request, $context);
129+
} catch (TimeoutException|CanceledException $e) {
130+
throw WorkflowUpdateRPCTimeoutOrCanceledException::fromTimeoutOrCanceledException($e);
131+
}
132+
133+
// Workflow Uprate accepted
134+
$result = $response->getOutcome();
135+
136+
/**
137+
* Retry the request.
138+
*
139+
* TimeoutException will be thrown in {@see \Temporal\Client\GRPC\BaseClient::call()} method
140+
* because the deadline is provided in the context.
141+
* That's why the deadline condition is not checked here.
142+
*/
143+
} while ($result === null);
129144

130145
// Accepted with result
131-
if ($result->getSuccess() !== null) {
132-
$this->result = EncodedValues::fromPayloads($result->getSuccess(), $this->converter);
146+
$success = $result->getSuccess();
147+
if ($success !== null) {
148+
$this->result = EncodedValues::fromPayloads($success, $this->converter);
133149
return;
134150
}
135151

src/Exception/Failure/FailureConverter.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
namespace Temporal\Exception\Failure;
1313

14-
use Psr\Log\LoggerInterface;
1514
use Temporal\Api\Common\V1\ActivityType;
1615
use Temporal\Api\Common\V1\WorkflowExecution;
1716
use Temporal\Api\Common\V1\WorkflowType;
@@ -30,8 +29,6 @@
3029

3130
final class FailureConverter
3231
{
33-
private static ?LoggerInterface $logger;
34-
3532
public static function mapFailureToException(Failure $failure, DataConverterInterface $converter): TemporalFailure
3633
{
3734
$e = self::createFailureException($failure, $converter);
@@ -160,11 +157,6 @@ public static function mapExceptionToFailure(\Throwable $e, DataConverterInterfa
160157
return $failure;
161158
}
162159

163-
public function setLogger(LoggerInterface $logger): void
164-
{
165-
self::$logger = $logger;
166-
}
167-
168160
private static function createFailureException(Failure $failure, DataConverterInterface $converter): TemporalFailure
169161
{
170162
$previous = null;

0 commit comments

Comments
 (0)