Skip to content

Commit e797994

Browse files
andreasasproulorensrbergundy
authored
fix(client): Add missing error handling and interceptors for workflow describe (#484)
* fix(client): Add missing error handling and interceptors for workflow describe * Update packages/client/src/interceptors.ts Co-authored-by: Roey Berman <[email protected]> * Update packages/client/src/interceptors.ts Co-authored-by: Roey Berman <[email protected]> * Add Workflow result interceptor to Client * Revert "Add Workflow result interceptor to Client" This reverts commit 0df3fd4. * Remove firstExecutionRunId Co-authored-by: Loren ☺️ <[email protected]> Co-authored-by: Roey Berman <[email protected]> Co-authored-by: Loren 🤓 <[email protected]>
1 parent 6e65a57 commit e797994

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

packages/client/src/interceptors.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
* @module
55
*/
66

7-
import { Next, Headers } from '@temporalio/internal-workflow-common';
7+
import { Headers, Next } from '@temporalio/internal-workflow-common';
88
import { temporal } from '@temporalio/proto';
9+
import {
10+
DescribeWorkflowExecutionResponse,
11+
RequestCancelWorkflowExecutionResponse,
12+
TerminateWorkflowExecutionResponse,
13+
WorkflowExecution,
14+
} from './types';
915
import { CompiledWorkflowOptions } from './workflow-options';
10-
import { RequestCancelWorkflowExecutionResponse, TerminateWorkflowExecutionResponse, WorkflowExecution } from './types';
1116

1217
export { Next, Headers };
1318

@@ -57,6 +62,11 @@ export interface WorkflowCancelInput {
5762
readonly firstExecutionRunId?: string;
5863
}
5964

65+
/** Input for WorkflowClientCallsInterceptor.describe */
66+
export interface WorkflowDescribeInput {
67+
readonly workflowExecution: WorkflowExecution;
68+
}
69+
6070
/**
6171
* Implement any of these methods to intercept WorkflowClient outbound calls
6272
*/
@@ -94,6 +104,10 @@ export interface WorkflowClientCallsInterceptor {
94104
* Intercept a service call to requestCancelWorkflowExecution
95105
*/
96106
cancel?: (input: WorkflowCancelInput, next: Next<this, 'cancel'>) => Promise<RequestCancelWorkflowExecutionResponse>;
107+
/**
108+
* Intercept a service call to describeWorkflowExecution
109+
*/
110+
describe?: (input: WorkflowDescribeInput, next: Next<this, 'describe'>) => Promise<DescribeWorkflowExecutionResponse>;
97111
}
98112

99113
interface WorkflowClientCallsInterceptorFactoryInput {

packages/client/src/workflow-client.ts

+21-8
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
WorkflowCancelInput,
4444
WorkflowClientCallsInterceptor,
4545
WorkflowClientInterceptors,
46+
WorkflowDescribeInput,
4647
WorkflowQueryInput,
4748
WorkflowSignalInput,
4849
WorkflowSignalWithStartInput,
@@ -711,6 +712,22 @@ export class WorkflowClient {
711712
}
712713
}
713714

715+
/**
716+
* Uses given input to make describeWorkflowExecution call to the service
717+
*
718+
* Used as the final function of the describe interceptor chain
719+
*/
720+
protected async _describeWorkflowHandler(input: WorkflowDescribeInput): Promise<DescribeWorkflowExecutionResponse> {
721+
try {
722+
return await this.service.describeWorkflowExecution({
723+
namespace: this.options.namespace,
724+
execution: input.workflowExecution,
725+
});
726+
} catch (err) {
727+
this.rethrowGrpcError(err, input.workflowExecution, 'Failed to describe workflow');
728+
}
729+
}
730+
714731
/**
715732
* Create a new workflow handle for new or existing Workflow execution
716733
*/
@@ -722,8 +739,6 @@ export class WorkflowClient {
722739
runIdForResult,
723740
...resultOptions
724741
}: WorkflowHandleOptions): WorkflowHandle<T> {
725-
const namespace = this.options.namespace;
726-
727742
return {
728743
client: this,
729744
workflowId,
@@ -748,12 +763,10 @@ export class WorkflowClient {
748763
});
749764
},
750765
async describe() {
751-
return this.client.service.describeWorkflowExecution({
752-
namespace,
753-
execution: {
754-
runId,
755-
workflowId,
756-
},
766+
const next = this.client._describeWorkflowHandler.bind(this.client);
767+
const fn = interceptors.length ? composeInterceptors(interceptors, 'describe', next) : next;
768+
return await fn({
769+
workflowExecution: { workflowId, runId },
757770
});
758771
},
759772
async signal<Args extends any[]>(def: SignalDefinition<Args> | string, ...args: Args): Promise<void> {

0 commit comments

Comments
 (0)