Skip to content

Commit a9b58cf

Browse files
authored
Fix getUpdateHandle API (#1320)
* Fixes a mistake in the recently-introduced update `workflowHandle.getUpdateHandle(...)` API #1312. It should not take `workflowId` as an argument since the appropriate `workflowId` is the one on the `workflowHandle`. * Also remove `GetWorkflowUpdateHandleOptions` for now.
1 parent 840fc36 commit a9b58cf

File tree

2 files changed

+24
-23
lines changed

2 files changed

+24
-23
lines changed

packages/client/src/workflow-client.ts

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,9 @@ export interface WorkflowHandle<T extends Workflow = Workflow> extends BaseWorkf
165165
): Promise<WorkflowUpdateHandle<Ret>>;
166166

167167
/**
168-
* Get a handle to an Update.
168+
* Get a handle to an Update of this Workflow.
169169
*/
170-
getUpdateHandle<Ret>(
171-
updateId: string,
172-
workflowId: string,
173-
options?: GetWorkflowUpdateHandleOptions
174-
): WorkflowUpdateHandle<Ret>;
170+
getUpdateHandle<Ret>(updateId: string): WorkflowUpdateHandle<Ret>;
175171

176172
/**
177173
* Query a running or completed Workflow.
@@ -476,7 +472,7 @@ export class WorkflowClient extends BaseClient {
476472

477473
/**
478474
* Sends a signal to a running Workflow or starts a new one if not already running and immediately signals it.
479-
* Useful when you're unsure of the Workflows' run state.
475+
* Useful when you're unsure of the Workflow's run state.
480476
*
481477
* @returns the runId of the Workflow
482478
*/
@@ -799,10 +795,9 @@ export class WorkflowClient extends BaseClient {
799795
protected createWorkflowUpdateHandle<Ret>(
800796
updateId: string,
801797
workflowId: string,
802-
options?: GetWorkflowUpdateHandleOptions,
798+
workflowRunId?: string,
803799
outcome?: temporal.api.update.v1.IOutcome
804800
): WorkflowUpdateHandle<Ret> {
805-
const workflowRunId = options?.workflowRunId;
806801
return {
807802
updateId,
808803
workflowId,
@@ -1077,7 +1072,7 @@ export class WorkflowClient extends BaseClient {
10771072
return this.createWorkflowUpdateHandle<Ret>(
10781073
output.updateId,
10791074
input.workflowExecution.workflowId,
1080-
{ workflowRunId: output.workflowRunId },
1075+
output.workflowRunId,
10811076
output.outcome
10821077
);
10831078
};
@@ -1156,12 +1151,8 @@ export class WorkflowClient extends BaseClient {
11561151
);
11571152
return await handle.result();
11581153
},
1159-
getUpdateHandle<Ret>(
1160-
updateId: string,
1161-
workflowId: string,
1162-
options?: GetWorkflowUpdateHandleOptions
1163-
): WorkflowUpdateHandle<Ret> {
1164-
return this.client.createWorkflowUpdateHandle(updateId, workflowId, options);
1154+
getUpdateHandle<Ret>(updateId: string): WorkflowUpdateHandle<Ret> {
1155+
return this.client.createWorkflowUpdateHandle(updateId, workflowId, runId);
11651156
},
11661157
async signal<Args extends any[]>(def: SignalDefinition<Args> | string, ...args: Args): Promise<void> {
11671158
const next = this.client._signalWorkflowHandler.bind(this.client);

packages/test/src/test-integration-update.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,28 @@ test('Update handle can be created from identifiers and used to obtain result',
6969
const wfHandle = await startWorkflow(workflowWithUpdates);
7070
const updateHandleFromStartUpdate = await wfHandle.startUpdate(update, { args: ['1'], updateId });
7171

72-
const updateHandle = wfHandle.getUpdateHandle(updateId, wfHandle.workflowId);
72+
// Obtain update handle on workflow handle from start update.
73+
const updateHandle = wfHandle.getUpdateHandle(updateId);
7374
t.deepEqual(await updateHandle.result(), ['1']);
7475

76+
// Obtain update handle on manually-created workflow handle with no run id.
7577
t.truthy(updateHandleFromStartUpdate.workflowRunId);
76-
const updateHandle2 = wfHandle.getUpdateHandle(updateId, wfHandle.workflowId, {
77-
workflowRunId: updateHandleFromStartUpdate.workflowRunId,
78-
});
78+
const freshWorkflowHandleWithoutRunId = t.context.env.client.workflow.getHandle(wfHandle.workflowId);
79+
const updateHandle2 = freshWorkflowHandleWithoutRunId.getUpdateHandle(updateId);
7980
t.deepEqual(await updateHandle2.result(), ['1']);
8081

81-
const incorrectRunId = wf.uuid4();
82-
const updateHandle3 = wfHandle.getUpdateHandle(updateId, wfHandle.workflowId, { workflowRunId: incorrectRunId });
83-
const err = await t.throwsAsync(updateHandle3.result());
82+
// Obtain update handle on manually-created workflow handle with run id.
83+
const freshWorkflowHandleWithRunId = t.context.env.client.workflow.getHandle(
84+
wfHandle.workflowId,
85+
updateHandleFromStartUpdate.workflowRunId
86+
);
87+
const updateHandle3 = freshWorkflowHandleWithRunId.getUpdateHandle(updateId);
88+
t.deepEqual(await updateHandle3.result(), ['1']);
89+
90+
// Obtain update handle on manually-created workflow handle with incorrect run id.
91+
const workflowHandleWithIncorrectRunId = t.context.env.client.workflow.getHandle(wfHandle.workflowId, wf.uuid4());
92+
const updateHandle4 = workflowHandleWithIncorrectRunId.getUpdateHandle(updateId);
93+
const err = await t.throwsAsync(updateHandle4.result());
8494
t.true(isGrpcServiceError(err) && err.code === grpcStatus.NOT_FOUND);
8595
});
8696
});

0 commit comments

Comments
 (0)