Skip to content

Commit a3c2ace

Browse files
committed
Process a case when workflow is started but update failed
1 parent 57c2e0a commit a3c2ace

File tree

3 files changed

+28
-15
lines changed

3 files changed

+28
-15
lines changed

src/Client/WorkflowClient.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,19 @@ public function updateWithStart(
235235
);
236236
$workflowStub->hasExecution() and throw new InvalidArgumentException(self::ERROR_WORKFLOW_START_DUPLICATION);
237237

238-
$handle = $this->getStarter()->updateWithStart(
238+
[$execution, $handle] = $this->getStarter()->updateWithStart(
239239
$workflowType,
240240
$workflowStub->getOptions() ?? WorkflowOptions::new(),
241241
$update,
242242
$updateArgs,
243243
$startArgs,
244244
);
245245

246-
// todo: set execution if UpdateWorkflow was failed but WF was started
247-
$workflowStub->setExecution($handle->getExecution());
246+
$workflowStub->setExecution($execution);
248247

249-
return $handle;
248+
return $handle instanceof \Throwable
249+
? throw $handle
250+
: $handle;
250251
}
251252

252253
public function newWorkflowStub(

src/Client/WorkflowStubInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
*/
3333
interface WorkflowStubInterface extends WorkflowRunInterface
3434
{
35+
/**
36+
* @return non-empty-string|null
37+
*/
3538
public function getWorkflowType(): ?string;
3639

3740
/**

src/Internal/Client/WorkflowStarter.php

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -122,18 +122,23 @@ function (SignalWithStartInput $input): WorkflowExecution {
122122
);
123123
}
124124

125+
/**
126+
* @param non-empty-string $workflowType
127+
*
128+
* @return array{WorkflowExecution, UpdateHandle|\Throwable}
129+
*/
125130
public function updateWithStart(
126131
string $workflowType,
127132
WorkflowOptions $options,
128133
UpdateOptions $update,
129134
array $updateArgs = [],
130135
array $startArgs = [],
131-
): UpdateHandle {
136+
): array {
132137
$arguments = EncodedValues::fromValues($startArgs, $this->converter);
133138
$updateArguments = EncodedValues::fromValues($updateArgs, $this->converter);
134139

135140
return $this->interceptors->with(
136-
function (UpdateWithStartInput $input): UpdateHandle {
141+
function (UpdateWithStartInput $input): array {
137142
$startRequest = $this->configureExecutionRequest(
138143
new StartWorkflowExecutionRequest(),
139144
$input->workflowStartInput,
@@ -216,15 +221,19 @@ function (UpdateWithStartInput $input): UpdateHandle {
216221
$updateResponse = $responses[1]->getUpdateWorkflow();
217222
\assert($updateResponse !== null);
218223

219-
$updateResult = (new \Temporal\Internal\Client\ResponseToResultMapper($this->converter))
220-
->mapUpdateWorkflowResponse(
221-
$updateResponse,
222-
updateName: $input->updateInput->updateName,
223-
workflowType: $input->workflowStartInput->workflowType,
224-
workflowExecution: $execution,
225-
);
224+
try {
225+
$updateResult = (new \Temporal\Internal\Client\ResponseToResultMapper($this->converter))
226+
->mapUpdateWorkflowResponse(
227+
$updateResponse,
228+
updateName: $input->updateInput->updateName,
229+
workflowType: $input->workflowStartInput->workflowType,
230+
workflowExecution: $execution,
231+
);
232+
} catch (\RuntimeException $e) {
233+
return [$execution, $e];
234+
}
226235

227-
return new UpdateHandle(
236+
return [$execution, new UpdateHandle(
228237
client: $this->serviceClient,
229238
clientOptions: $this->clientOptions,
230239
converter: $this->converter,
@@ -234,7 +243,7 @@ function (UpdateWithStartInput $input): UpdateHandle {
234243
resultType: $input->updateInput->resultType,
235244
updateId: $updateResult->getReference()->updateId,
236245
result: $updateResult->getResult(),
237-
);
246+
)];
238247
},
239248
/** @see WorkflowClientCallsInterceptor::updateWithStart() */
240249
'updateWithStart',

0 commit comments

Comments
 (0)