Skip to content

Commit 70e6c21

Browse files
authored
update idl for query API (#224)
1 parent 5cba128 commit 70e6c21

File tree

8 files changed

+2808
-162
lines changed

8 files changed

+2808
-162
lines changed

.gen/go/cadence/cadence.go

Lines changed: 1381 additions & 24 deletions
Large diffs are not rendered by default.

.gen/go/cadence/tchan-cadence.go

Lines changed: 360 additions & 136 deletions
Large diffs are not rendered by default.

.gen/go/shared/shared.go

Lines changed: 937 additions & 0 deletions
Large diffs are not rendered by default.

common/metrics/service_wrapper.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const (
6363
scopeNameStartWorkflowExecution = CadenceMetricsPrefix + "StartWorkflowExecution"
6464
scopeNameTerminateWorkflowExecution = CadenceMetricsPrefix + "TerminateWorkflowExecution"
6565
scopeNameUpdateDomain = CadenceMetricsPrefix + "UpdateDomain"
66+
scopeNameQueryWorkflow = CadenceMetricsPrefix + "QueryWorkflow"
67+
scopeNameRespondQueryTaskCompleted = CadenceMetricsPrefix + "RespondQueryTaskCompleted"
6668
)
6769

6870
// NewWorkflowServiceWrapper creates a new wrapper to WorkflowService that will emit metrics for each service call.
@@ -97,7 +99,8 @@ func (s *operationScope) handleError(err error) {
9799
case *shared.EntityNotExistsError,
98100
*shared.BadRequestError,
99101
*shared.DomainAlreadyExistsError,
100-
*shared.WorkflowExecutionAlreadyStartedError:
102+
*shared.WorkflowExecutionAlreadyStartedError,
103+
*shared.QueryFailedError:
101104
s.scope.Counter(CadenceInvalidRequest).Inc(1)
102105
default:
103106
s.scope.Counter(CadenceError).Inc(1)
@@ -230,3 +233,17 @@ func (w *workflowServiceMetricsWrapper) UpdateDomain(ctx thrift.Context, request
230233
scope.handleError(err)
231234
return result, err
232235
}
236+
237+
func (w *workflowServiceMetricsWrapper) QueryWorkflow(ctx thrift.Context, request *shared.QueryWorkflowRequest) (*shared.QueryWorkflowResponse, error) {
238+
scope := w.getOperationScope(scopeNameQueryWorkflow)
239+
result, err := w.service.QueryWorkflow(ctx, request)
240+
scope.handleError(err)
241+
return result, err
242+
}
243+
244+
func (w *workflowServiceMetricsWrapper) RespondQueryTaskCompleted(ctx thrift.Context, request *shared.RespondQueryTaskCompletedRequest) error {
245+
scope := w.getOperationScope(scopeNameRespondQueryTaskCompleted)
246+
err := w.service.RespondQueryTaskCompleted(ctx, request)
247+
scope.handleError(err)
248+
return err
249+
}

common/metrics/service_wrapper_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ func Test_Wrapper(t *testing.T) {
6767
{"PollForActivityTask", []interface{}{ctx, &s.PollForActivityTaskRequest{}}, []interface{}{nil, &s.EntityNotExistsError{}}, []string{CadenceRequest, CadenceInvalidRequest}},
6868
// one case of server error
6969
{"PollForActivityTask", []interface{}{ctx, &s.PollForActivityTaskRequest{}}, []interface{}{nil, &s.InternalServiceError{}}, []string{CadenceRequest, CadenceError}},
70+
{"QueryWorkflow", []interface{}{ctx, &s.QueryWorkflowRequest{}}, []interface{}{nil, &s.InternalServiceError{}}, []string{CadenceRequest, CadenceError}},
71+
{"RespondQueryTaskCompleted", []interface{}{ctx, &s.RespondQueryTaskCompletedRequest{}}, []interface{}{nil, &s.InternalServiceError{}}, []string{CadenceRequest, CadenceError}},
7072
}
7173

7274
for _, test := range tests {

idl/github.com/uber/cadence/cadence.thrift

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ service WorkflowService {
8787
1: shared.BadRequestError badRequestError,
8888
2: shared.InternalServiceError internalServiceError,
8989
3: shared.WorkflowExecutionAlreadyStartedError sessionAlreadyExistError,
90+
4: shared.ServiceBusyError serviceBusyError,
9091
)
9192

9293
/**
@@ -98,6 +99,7 @@ service WorkflowService {
9899
1: shared.BadRequestError badRequestError,
99100
2: shared.InternalServiceError internalServiceError,
100101
3: shared.EntityNotExistsError entityNotExistError,
102+
4: shared.ServiceBusyError serviceBusyError,
101103
)
102104

103105
/**
@@ -111,6 +113,7 @@ service WorkflowService {
111113
throws (
112114
1: shared.BadRequestError badRequestError,
113115
2: shared.InternalServiceError internalServiceError,
116+
3: shared.ServiceBusyError serviceBusyError,
114117
)
115118

116119
/**
@@ -140,6 +143,7 @@ service WorkflowService {
140143
throws (
141144
1: shared.BadRequestError badRequestError,
142145
2: shared.InternalServiceError internalServiceError,
146+
3: shared.ServiceBusyError serviceBusyError,
143147
)
144148

145149
/**
@@ -209,6 +213,8 @@ service WorkflowService {
209213
1: shared.BadRequestError badRequestError,
210214
2: shared.InternalServiceError internalServiceError,
211215
3: shared.EntityNotExistsError entityNotExistError,
216+
4: shared.CancellationAlreadyRequestedError cancellationAlreadyRequestedError,
217+
5: shared.ServiceBusyError serviceBusyError,
212218
)
213219

214220
/**
@@ -220,6 +226,7 @@ service WorkflowService {
220226
1: shared.BadRequestError badRequestError,
221227
2: shared.InternalServiceError internalServiceError,
222228
3: shared.EntityNotExistsError entityNotExistError,
229+
4: shared.ServiceBusyError serviceBusyError,
223230
)
224231

225232
/**
@@ -231,6 +238,7 @@ service WorkflowService {
231238
1: shared.BadRequestError badRequestError,
232239
2: shared.InternalServiceError internalServiceError,
233240
3: shared.EntityNotExistsError entityNotExistError,
241+
4: shared.ServiceBusyError serviceBusyError,
234242
)
235243

236244
/**
@@ -241,6 +249,7 @@ service WorkflowService {
241249
1: shared.BadRequestError badRequestError,
242250
2: shared.InternalServiceError internalServiceError,
243251
3: shared.EntityNotExistsError entityNotExistError,
252+
4: shared.ServiceBusyError serviceBusyError,
244253
)
245254

246255
/**
@@ -251,5 +260,30 @@ service WorkflowService {
251260
1: shared.BadRequestError badRequestError,
252261
2: shared.InternalServiceError internalServiceError,
253262
3: shared.EntityNotExistsError entityNotExistError,
263+
4: shared.ServiceBusyError serviceBusyError,
254264
)
255-
}
265+
266+
/**
267+
* RespondQueryTaskCompleted is called by application worker to complete a QueryTask (which is a DecisionTask for query)
268+
* as a result of 'PollForDecisionTask' API call. Completing a QueryTask will unblock the client call to 'QueryWorkflow'
269+
* API and return the query result to client as a response to 'QueryWorkflow' API call.
270+
**/
271+
void RespondQueryTaskCompleted(1: shared.RespondQueryTaskCompletedRequest completeRequest)
272+
throws (
273+
1: shared.BadRequestError badRequestError,
274+
2: shared.InternalServiceError internalServiceError,
275+
3: shared.EntityNotExistsError entityNotExistError,
276+
)
277+
278+
/**
279+
* QueryWorkflow returns query result for a specified workflow execution
280+
**/
281+
shared.QueryWorkflowResponse QueryWorkflow(1: shared.QueryWorkflowRequest queryRequest)
282+
throws (
283+
1: shared.BadRequestError badRequestError,
284+
2: shared.InternalServiceError internalServiceError,
285+
3: shared.EntityNotExistsError entityNotExistError,
286+
4: shared.QueryFailedError queryFailedError,
287+
)
288+
289+
}

idl/github.com/uber/cadence/shared.thrift

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ exception ServiceBusyError {
4646
1: required string message
4747
}
4848

49+
exception CancellationAlreadyRequestedError {
50+
1: required string message
51+
}
52+
53+
exception QueryFailedError {
54+
1: required string message
55+
}
56+
4957
enum DomainStatus {
5058
REGISTERED,
5159
DEPRECATED,
@@ -126,6 +134,7 @@ enum DecisionTaskFailedCause {
126134
BAD_CANCEL_WORKFLOW_EXECUTION_ATTRIBUTES,
127135
BAD_REQUEST_CANCEL_EXTERNAL_WORKFLOW_EXECUTION_ATTRIBUTES,
128136
BAD_CONTINUE_AS_NEW_ATTRIBUTES,
137+
START_TIMER_DUPLICATE_ID,
129138
}
130139

131140
enum CancelExternalWorkflowExecutionFailedCause {
@@ -151,6 +160,11 @@ enum ChildPolicy {
151160
ABANDON,
152161
}
153162

163+
enum QueryTaskCompletedType {
164+
COMPLETED,
165+
FAILED,
166+
}
167+
154168
struct WorkflowType {
155169
10: optional string name
156170
}
@@ -679,6 +693,7 @@ struct PollForDecisionTaskResponse {
679693
50: optional i64 (js.type = "Long") startedEventId
680694
60: optional History history
681695
70: optional binary nextPageToken
696+
80: optional WorkflowQuery query
682697
}
683698

684699
struct RespondDecisionTaskCompletedRequest {
@@ -741,6 +756,7 @@ struct RequestCancelWorkflowExecutionRequest {
741756
10: optional string domain
742757
20: optional WorkflowExecution workflowExecution
743758
30: optional string identity
759+
40: optional string requestId
744760
}
745761

746762
struct GetWorkflowExecutionHistoryRequest {
@@ -799,3 +815,25 @@ struct ListClosedWorkflowExecutionsResponse {
799815
10: optional list<WorkflowExecutionInfo> executions
800816
20: optional binary nextPageToken
801817
}
818+
819+
struct QueryWorkflowRequest {
820+
10: optional string domain
821+
20: optional WorkflowExecution execution
822+
30: optional WorkflowQuery query
823+
}
824+
825+
struct QueryWorkflowResponse {
826+
10: optional binary queryResult
827+
}
828+
829+
struct WorkflowQuery {
830+
10: optional string queryType
831+
20: optional binary queryArgs
832+
}
833+
834+
struct RespondQueryTaskCompletedRequest {
835+
10: optional binary taskToken
836+
20: optional QueryTaskCompletedType completedType
837+
30: optional binary queryResult
838+
40: optional string errorMessage
839+
}

mocks/TChanWorkflowService.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,4 +363,41 @@ func (_m *TChanWorkflowService) UpdateDomain(ctx thrift.Context, updateRequest *
363363
return r0, r1
364364
}
365365

366+
// UpdateDomain provides a mock function with given fields: ctx, updateRequest
367+
func (_m *TChanWorkflowService) QueryWorkflow(ctx thrift.Context, queryRequest *shared.QueryWorkflowRequest) (*shared.QueryWorkflowResponse, error) {
368+
ret := _m.Called(ctx, queryRequest)
369+
370+
var r0 *shared.QueryWorkflowResponse
371+
if rf, ok := ret.Get(0).(func(thrift.Context, *shared.QueryWorkflowRequest) *shared.QueryWorkflowResponse); ok {
372+
r0 = rf(ctx, queryRequest)
373+
} else {
374+
if ret.Get(0) != nil {
375+
r0 = ret.Get(0).(*shared.QueryWorkflowResponse)
376+
}
377+
}
378+
379+
var r1 error
380+
if rf, ok := ret.Get(1).(func(thrift.Context, *shared.QueryWorkflowRequest) error); ok {
381+
r1 = rf(ctx, queryRequest)
382+
} else {
383+
r1 = ret.Error(1)
384+
}
385+
386+
return r0, r1
387+
}
388+
389+
// RespondQueryTaskCompleted provides a mock function with given fields: ctx, completeRequest
390+
func (_m *TChanWorkflowService) RespondQueryTaskCompleted(ctx thrift.Context, completeRequest *shared.RespondQueryTaskCompletedRequest) error {
391+
ret := _m.Called(ctx, completeRequest)
392+
393+
var r0 error
394+
if rf, ok := ret.Get(1).(func(thrift.Context, *shared.RespondQueryTaskCompletedRequest) error); ok {
395+
r0 = rf(ctx, completeRequest)
396+
} else {
397+
r0 = ret.Error(1)
398+
}
399+
400+
return r0
401+
}
402+
366403
var _ cadence.TChanWorkflowService = (*TChanWorkflowService)(nil)

0 commit comments

Comments
 (0)