Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose QueryRejectedError #1616

Merged
merged 3 commits into from
Sep 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions interceptor/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ type ScheduleClientCreateInput = internal.ScheduleClientCreateInput
// ClientOutoundInterceptor.UpdateWorkflow.
type ClientUpdateWorkflowInput = internal.ClientUpdateWorkflowInput

// QueryRejectedError is a possible error that can be returned by
// ClientOutboundInterceptor.QueryWorkflow to indicate that the query was rejected by the server.
type QueryRejectedError = internal.QueryRejectedError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arguably may be better to expose in temporal package.


// Header provides Temporal header information from the context for reading or
// writing during specific interceptor calls.
//
Expand Down
1 change: 1 addition & 0 deletions internal/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ type ClientOutboundInterceptor interface {
TerminateWorkflow(context.Context, *ClientTerminateWorkflowInput) error

// QueryWorkflow intercepts client.Client.QueryWorkflow.
// If the query is rejected, QueryWorkflow will return an QueryRejectedError
// interceptor.Header will return a non-nil map for this context.
QueryWorkflow(context.Context, *ClientQueryWorkflowInput) (converter.EncodedValue, error)

Expand Down
17 changes: 11 additions & 6 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ type (
paginate func(nexttoken []byte) (*workflowservice.GetWorkflowExecutionHistoryResponse, error)
}

// queryRejectedError is a wrapper for QueryRejected
queryRejectedError struct {
// QueryRejectedError is a wrapper for QueryRejected
QueryRejectedError struct {
queryRejected *querypb.QueryRejected
}
)
Expand Down Expand Up @@ -924,9 +924,10 @@ func (wc *WorkflowClient) QueryWorkflowWithOptions(ctx context.Context, request
QueryRejectCondition: request.QueryRejectCondition,
})
if err != nil {
if err, ok := err.(*queryRejectedError); ok {
var qerr *QueryRejectedError
if errors.As(err, &qerr) {
return &QueryWorkflowWithOptionsResponse{
QueryRejected: err.queryRejected,
QueryRejected: qerr.QueryRejected(),
}, nil
}
return nil, err
Expand Down Expand Up @@ -1994,7 +1995,7 @@ func (w *workflowClientInterceptor) QueryWorkflow(
}

if resp.QueryRejected != nil {
return nil, &queryRejectedError{
return nil, &QueryRejectedError{
queryRejected: resp.QueryRejected,
}
}
Expand Down Expand Up @@ -2241,7 +2242,11 @@ func (luh *lazyUpdateHandle) Get(ctx context.Context, valuePtr interface{}) erro
return resp.Result.Get(valuePtr)
}

func (q *queryRejectedError) Error() string {
func (q *QueryRejectedError) QueryRejected() *querypb.QueryRejected {
return q.queryRejected
}

func (q *QueryRejectedError) Error() string {
return fmt.Sprintf("query rejected: %s", q.queryRejected.Status.String())
}

Expand Down
Loading