Skip to content

Commit

Permalink
Use single input struct in interceptor signature
Browse files Browse the repository at this point in the history
  • Loading branch information
dandavison committed Dec 5, 2024
1 parent a407084 commit 0f98512
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
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

// ClientUpdateWithStartWorkflowInput is input for
// ClientOutboundInterceptor.UpdateWithStartWorkflow.
type ClientUpdateWithStartWorkflowInput = internal.ClientUpdateWithStartWorkflowInput

// Header provides Temporal header information from the context for reading or
// writing during specific interceptor calls.
//
Expand Down
11 changes: 5 additions & 6 deletions interceptor/tracing_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,18 +381,17 @@ func (t *tracingClientOutboundInterceptor) UpdateWorkflow(

func (t *tracingClientOutboundInterceptor) UpdateWithStartWorkflow(
ctx context.Context,
in *ClientUpdateWorkflowInput,
startOperation client.WithStartWorkflowOperation,
in *ClientUpdateWithStartWorkflowInput,
) (client.WorkflowUpdateHandle, error) {
// Only add tracing if enabled
if t.root.options.DisableUpdateTracing {
return t.Next.UpdateWithStartWorkflow(ctx, in, startOperation)
return t.Next.UpdateWithStartWorkflow(ctx, in)
}
// Start span and write to header
span, ctx, err := t.root.startSpanFromContext(ctx, &TracerStartSpanOptions{
Operation: "UpdateWithStartWorkflow",
Name: in.UpdateName,
Tags: map[string]string{workflowIDTagKey: in.WorkflowID, updateIDTagKey: in.UpdateID},
Name: in.UpdateInput.UpdateName,
Tags: map[string]string{workflowIDTagKey: in.UpdateInput.WorkflowID, updateIDTagKey: in.UpdateInput.UpdateID},
ToHeader: true,
Time: time.Now(),
})
Expand All @@ -402,7 +401,7 @@ func (t *tracingClientOutboundInterceptor) UpdateWithStartWorkflow(
var finishOpts TracerFinishSpanOptions
defer span.Finish(&finishOpts)

val, err := t.Next.UpdateWithStartWorkflow(ctx, in, startOperation)
val, err := t.Next.UpdateWithStartWorkflow(ctx, in)
finishOpts.Error = err
return val, err
}
Expand Down
7 changes: 6 additions & 1 deletion internal/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ type ClientOutboundInterceptor interface {
// UpdateWithStartWorkflow intercepts client.Client.UpdateWithStartWorkflow.
//
// NOTE: Experimental
UpdateWithStartWorkflow(context.Context, *ClientUpdateWorkflowInput, WithStartWorkflowOperation) (WorkflowUpdateHandle, error)
UpdateWithStartWorkflow(context.Context, *ClientUpdateWithStartWorkflowInput) (WorkflowUpdateHandle, error)

// PollWorkflowUpdate requests the outcome of a specific update from the
// server.
Expand All @@ -421,6 +421,11 @@ type ClientUpdateWorkflowInput struct {
WaitForStage WorkflowUpdateStage
}

type ClientUpdateWithStartWorkflowInput struct {
UpdateInput *ClientUpdateWorkflowInput
StartWorkflowOperation WithStartWorkflowOperation
}

// ClientPollWorkflowUpdateInput is the input to
// ClientOutboundInterceptor.PollWorkflowUpdate.
type ClientPollWorkflowUpdateInput struct {
Expand Down
5 changes: 2 additions & 3 deletions internal/interceptor_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,10 +487,9 @@ func (c *ClientOutboundInterceptorBase) PollWorkflowUpdate(

func (c *ClientOutboundInterceptorBase) UpdateWithStartWorkflow(
ctx context.Context,
in *ClientUpdateWorkflowInput,
startOperation WithStartWorkflowOperation,
in *ClientUpdateWithStartWorkflowInput,
) (WorkflowUpdateHandle, error) {
return c.Next.UpdateWithStartWorkflow(ctx, in, startOperation)
return c.Next.UpdateWithStartWorkflow(ctx, in)
}

// ExecuteWorkflow implements ClientOutboundInterceptor.ExecuteWorkflow.
Expand Down
12 changes: 7 additions & 5 deletions internal/internal_workflow_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,10 @@ func (wc *WorkflowClient) UpdateWithStartWorkflow(

ctx = contextWithNewHeader(ctx)

return wc.interceptor.UpdateWithStartWorkflow(ctx, updateInput, startOp)
return wc.interceptor.UpdateWithStartWorkflow(ctx, &ClientUpdateWithStartWorkflowInput{
UpdateInput: updateInput,
StartWorkflowOperation: startOp,
})
}

// CheckHealthRequest is a request for Client.CheckHealth.
Expand Down Expand Up @@ -1736,10 +1739,9 @@ func (w *workflowClientInterceptor) ExecuteWorkflow(

func (w *workflowClientInterceptor) UpdateWithStartWorkflow(
ctx context.Context,
updateInput *ClientUpdateWorkflowInput,
startOperation WithStartWorkflowOperation,
in *ClientUpdateWithStartWorkflowInput,
) (WorkflowUpdateHandle, error) {
startOp, ok := startOperation.(*withStartWorkflowOperationImpl)
startOp, ok := in.StartWorkflowOperation.(*withStartWorkflowOperationImpl)
if !ok {
return nil, fmt.Errorf("%w: startOperation must be created by NewWithStartWorkflowOperation", errInvalidWithStartWorkflowOperation)
}
Expand All @@ -1757,7 +1759,7 @@ func (w *workflowClientInterceptor) UpdateWithStartWorkflow(
}

// Create update request
updateReq, err := w.createUpdateWorkflowRequest(ctx, updateInput)
updateReq, err := w.createUpdateWorkflowRequest(ctx, in.UpdateInput)
if err != nil {
return nil, fmt.Errorf("%w: %w", errInvalidWithStartWorkflowOperation, err)
}
Expand Down

0 comments on commit 0f98512

Please sign in to comment.