Skip to content

Commit

Permalink
Nexus interceptors (#1841)
Browse files Browse the repository at this point in the history
## What was changed

Added support for Nexus operation inbound and outbound interceptors. The implementation was a bit awkward and required a couple of adapters from and to the Nexus SDK middleware interfaces but that seems reasonable if we want to leverage shared code from that SDK.

## Why?

Support tracing and other use cases.

## Checklist

- [x] Upgrade to a stable Nexus SDK
- [x] Figure out if we want to also intercept logs and metrics emitted by the SDK outside of the "handler" scope - won't do
- [ ] Add tracing interceptor support - will do in a followup PR
  • Loading branch information
bergundy authored Feb 22, 2025
1 parent 1720257 commit d32c252
Show file tree
Hide file tree
Showing 26 changed files with 482 additions and 103 deletions.
2 changes: 1 addition & 1 deletion contrib/datadog/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/nexus-rpc/sdk-go v0.2.0 // indirect
github.com/nexus-rpc/sdk-go v0.3.0 // indirect
github.com/outcaste-io/ristretto v0.2.3 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/philhofer/fwd v1.1.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions contrib/datadog/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/nexus-rpc/sdk-go v0.2.0 h1:NKMkfTTQDEkbnP46/oB7cV7Ml25Wk+9w7lOyeYJQLAc=
github.com/nexus-rpc/sdk-go v0.2.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/nexus-rpc/sdk-go v0.3.0 h1:Y3B0kLYbMhd4C2u00kcYajvmOrfozEtTV/nHSnV57jA=
github.com/nexus-rpc/sdk-go v0.3.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
Expand Down
2 changes: 1 addition & 1 deletion contrib/opentelemetry/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
require (
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/nexus-rpc/sdk-go v0.2.0 // indirect
github.com/nexus-rpc/sdk-go v0.3.0 // indirect
golang.org/x/sync v0.8.0 // indirect
)

Expand Down
4 changes: 2 additions & 2 deletions contrib/opentelemetry/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/nexus-rpc/sdk-go v0.2.0 h1:NKMkfTTQDEkbnP46/oB7cV7Ml25Wk+9w7lOyeYJQLAc=
github.com/nexus-rpc/sdk-go v0.2.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/nexus-rpc/sdk-go v0.3.0 h1:Y3B0kLYbMhd4C2u00kcYajvmOrfozEtTV/nHSnV57jA=
github.com/nexus-rpc/sdk-go v0.3.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
Expand Down
2 changes: 1 addition & 1 deletion contrib/opentracing/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/nexus-rpc/sdk-go v0.2.0 // indirect
github.com/nexus-rpc/sdk-go v0.3.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/robfig/cron v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions contrib/opentracing/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/nexus-rpc/sdk-go v0.2.0 h1:NKMkfTTQDEkbnP46/oB7cV7Ml25Wk+9w7lOyeYJQLAc=
github.com/nexus-rpc/sdk-go v0.2.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/nexus-rpc/sdk-go v0.3.0 h1:Y3B0kLYbMhd4C2u00kcYajvmOrfozEtTV/nHSnV57jA=
github.com/nexus-rpc/sdk-go v0.3.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
Expand Down
2 changes: 1 addition & 1 deletion contrib/resourcetuner/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 // indirect
github.com/nexus-rpc/sdk-go v0.2.0 // indirect
github.com/nexus-rpc/sdk-go v0.3.0 // indirect
github.com/opencontainers/runtime-spec v1.0.2 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions contrib/resourcetuner/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0 h1:6E+4a0GO5zZEnZ81pIr0yLvtUWk2if982qA3F3QD6H4=
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
github.com/nexus-rpc/sdk-go v0.2.0 h1:NKMkfTTQDEkbnP46/oB7cV7Ml25Wk+9w7lOyeYJQLAc=
github.com/nexus-rpc/sdk-go v0.2.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/nexus-rpc/sdk-go v0.3.0 h1:Y3B0kLYbMhd4C2u00kcYajvmOrfozEtTV/nHSnV57jA=
github.com/nexus-rpc/sdk-go v0.3.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/opencontainers/runtime-spec v1.0.2 h1:UfAcuLBJB9Coz72x1hgl8O5RVzTdNiaglX6v2DM6FI0=
github.com/opencontainers/runtime-spec v1.0.2/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down
2 changes: 1 addition & 1 deletion contrib/tally/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/nexus-rpc/sdk-go v0.2.0 // indirect
github.com/nexus-rpc/sdk-go v0.3.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/robfig/cron v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions contrib/tally/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/nexus-rpc/sdk-go v0.2.0 h1:NKMkfTTQDEkbnP46/oB7cV7Ml25Wk+9w7lOyeYJQLAc=
github.com/nexus-rpc/sdk-go v0.2.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/nexus-rpc/sdk-go v0.3.0 h1:Y3B0kLYbMhd4C2u00kcYajvmOrfozEtTV/nHSnV57jA=
github.com/nexus-rpc/sdk-go v0.3.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/golang/mock v1.6.0
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
github.com/nexus-rpc/sdk-go v0.2.0
github.com/nexus-rpc/sdk-go v0.3.0
github.com/pborman/uuid v1.2.1
github.com/robfig/cron v1.2.0
github.com/stretchr/testify v1.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/nexus-rpc/sdk-go v0.2.0 h1:NKMkfTTQDEkbnP46/oB7cV7Ml25Wk+9w7lOyeYJQLAc=
github.com/nexus-rpc/sdk-go v0.2.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/nexus-rpc/sdk-go v0.3.0 h1:Y3B0kLYbMhd4C2u00kcYajvmOrfozEtTV/nHSnV57jA=
github.com/nexus-rpc/sdk-go v0.3.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
Expand Down
41 changes: 41 additions & 0 deletions interceptor/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,47 @@ type ClientUpdateWorkflowInput = internal.ClientUpdateWorkflowInput
// ClientOutboundInterceptor.UpdateWithStartWorkflow.
type ClientUpdateWithStartWorkflowInput = internal.ClientUpdateWithStartWorkflowInput

// NexusOperationInboundInterceptor is an interface for intercepting Nexus operation method invocations.
//
// All implementations must embed [NexusOperationInboundInterceptorBase] to safely handle future changes.
//
// Note: Experimental
type NexusOperationInboundInterceptor = internal.NexusOperationInboundInterceptor

// NexusOperationInboundInterceptorBase is a default implementation of [NexusOperationInboundInterceptor] that
// forwards calls to the next inbound interceptor and uses a [NexusOperationOutboundInterceptorBase] on Init.
//
// This must be embedded into all [NexusOperationInboundInterceptor] implementations to safely handle future changes.
//
// Note: Experimental
type NexusOperationInboundInterceptorBase = internal.NexusOperationInboundInterceptorBase

// NexusOperationOutboundInterceptor is an interface for intercepting methods in the temporalnexus package when called
// from within a Nexus Operation handler.
//
// All implementations must embed [NexusOperationOutboundInterceptorBase] to safely handle future changes.
//
// Note: Experimental
type NexusOperationOutboundInterceptor = internal.NexusOperationOutboundInterceptor

// NexusOperationOutboundInterceptorBase is a default implementation of [NexusOperationOutboundInterceptor] that
// forwards calls to the next outbound interceptor.
//
// This must be embedded into all [NexusOperationOutboundInterceptor] implementations to safely handle future changes.
//
// Note: Experimental
type NexusOperationOutboundInterceptorBase = internal.NexusOperationOutboundInterceptorBase

// NexusStartOperationInput is the input to NexusOperationInboundInterceptor.StartOperation.
//
// Note: Experimental
type NexusStartOperationInput = internal.NexusStartOperationInput

// NexusCancelOperationInput is the input to NexusOperationInboundInterceptor.CancelOperation.
//
// Note: Experimental
type NexusCancelOperationInput = internal.NexusCancelOperationInput

// Header provides Temporal header information from the context for reading or
// writing during specific interceptor calls.
//
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/build/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ require (
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.26.1 // indirect
github.com/nexus-rpc/sdk-go v0.2.0 // indirect
github.com/nexus-rpc/sdk-go v0.3.0 // indirect
github.com/pborman/uuid v1.2.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/robfig/cron v1.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/build/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/nexus-rpc/sdk-go v0.2.0 h1:NKMkfTTQDEkbnP46/oB7cV7Ml25Wk+9w7lOyeYJQLAc=
github.com/nexus-rpc/sdk-go v0.2.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/nexus-rpc/sdk-go v0.3.0 h1:Y3B0kLYbMhd4C2u00kcYajvmOrfozEtTV/nHSnV57jA=
github.com/nexus-rpc/sdk-go v0.3.0/go.mod h1:TpfkM2Cw0Rlk9drGkoiSMpFqflKTiQLWUNyKJjF8mKQ=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pborman/uuid v1.2.1 h1:+ZZIw58t/ozdjRaXh/3awHfmWRbzYxJoAdNJxe/3pvw=
github.com/pborman/uuid v1.2.1/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
Expand Down
58 changes: 58 additions & 0 deletions internal/interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type WorkerInterceptor interface {
// the next interceptor in the chain.
InterceptWorkflow(ctx Context, next WorkflowInboundInterceptor) WorkflowInboundInterceptor

InterceptNexusOperation(ctx context.Context, next NexusOperationInboundInterceptor) NexusOperationInboundInterceptor

mustEmbedWorkerInterceptorBase()
}

Expand Down Expand Up @@ -535,3 +537,59 @@ type ClientQueryWorkflowInput struct {
Args []interface{}
QueryRejectCondition enumspb.QueryRejectCondition
}

// NexusOutboundInterceptor intercepts Nexus operation method invocations. See documentation in the interceptor package
// for more details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.NexusOperationInboundInterceptor]
//
// NOTE: Experimental
type NexusOperationInboundInterceptor interface {
// Init is the first call of this interceptor. Implementations can change/wrap
// the outbound interceptor before calling Init on the next interceptor.
Init(ctx context.Context, outbound NexusOperationOutboundInterceptor) error

// StartOperation intercepts inbound Nexus StartOperation calls.
StartOperation(ctx context.Context, input NexusStartOperationInput) (nexus.HandlerStartOperationResult[any], error)
// StartOperation intercepts inbound Nexus CancelOperation calls.
CancelOperation(ctx context.Context, input NexusCancelOperationInput) error

mustEmbedNexusOperationInboundInterceptorBase()
}

// NexusOperationOutboundInterceptor intercepts methods exposed in the temporalnexus package. See documentation in the
// interceptor package for more details.
//
// Exposed as: [go.temporal.io/sdk/interceptor.NexusOperationOutboundInterceptor]
//
// Note: Experimental
type NexusOperationOutboundInterceptor interface {
// GetClient intercepts temporalnexus.GetClient.
GetClient(ctx context.Context) Client
// GetLogger intercepts temporalnexus.GetLogger.
GetLogger(ctx context.Context) log.Logger
// GetMetricsHandler intercepts temporalnexus.GetMetricsHandler.
GetMetricsHandler(ctx context.Context) metrics.Handler

mustEmbedNexusOperationOutboundInterceptorBase()
}

// NexusStartOperationInput is the input to NexusOperationInboundInterceptor.StartOperation.
//
// Exposed as: [go.temporal.io/sdk/interceptor.NexusStartOperationInput]
//
// Note: Experimental
type NexusStartOperationInput struct {
Input any
Options nexus.StartOperationOptions
}

// NexusCancelOperationInput is the input to NexusOperationInboundInterceptor.CancelOperation.
//
// Exposed as: [go.temporal.io/sdk/interceptor.NexusCancelOperationInput]
//
// Note: Experimental
type NexusCancelOperationInput struct {
Token string
Options nexus.CancelOperationOptions
}
62 changes: 62 additions & 0 deletions internal/interceptor_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"context"
"time"

"github.com/nexus-rpc/sdk-go/nexus"
"go.temporal.io/sdk/converter"
"go.temporal.io/sdk/internal/common/metrics"
"go.temporal.io/sdk/log"
Expand Down Expand Up @@ -65,6 +66,11 @@ func (*WorkerInterceptorBase) InterceptWorkflow(
return &WorkflowInboundInterceptorBase{Next: next}
}

// InterceptNexusOperation implements WorkerInterceptor.
func (w *WorkerInterceptorBase) InterceptNexusOperation(ctx context.Context, next NexusOperationInboundInterceptor) NexusOperationInboundInterceptor {
return &NexusOperationInboundInterceptorBase{Next: next}
}

func (*WorkerInterceptorBase) mustEmbedWorkerInterceptorBase() {}

// ActivityInboundInterceptorBase is a default implementation of
Expand Down Expand Up @@ -567,3 +573,59 @@ func (c *ClientOutboundInterceptorBase) CreateSchedule(ctx context.Context, in *
}

func (*ClientOutboundInterceptorBase) mustEmbedClientOutboundInterceptorBase() {}

// NexusOperationInboundInterceptorBase is a default implementation of [NexusOperationInboundInterceptor] that
// forwards calls to the next inbound interceptor.
//
// Note: Experimental
type NexusOperationInboundInterceptorBase struct {
Next NexusOperationInboundInterceptor
}

// CancelOperation implements NexusOperationInboundInterceptor.
func (n *NexusOperationInboundInterceptorBase) CancelOperation(ctx context.Context, input NexusCancelOperationInput) error {
return n.Next.CancelOperation(ctx, input)
}

// Init implements NexusOperationInboundInterceptor.
func (n *NexusOperationInboundInterceptorBase) Init(ctx context.Context, outbound NexusOperationOutboundInterceptor) error {
return n.Next.Init(ctx, outbound)
}

// StartOperation implements NexusOperationInboundInterceptor.
func (n *NexusOperationInboundInterceptorBase) StartOperation(ctx context.Context, input NexusStartOperationInput) (nexus.HandlerStartOperationResult[any], error) {
return n.Next.StartOperation(ctx, input)
}

// mustEmbedNexusOperationInboundInterceptorBase implements NexusOperationInboundInterceptor.
func (n *NexusOperationInboundInterceptorBase) mustEmbedNexusOperationInboundInterceptorBase() {}

var _ NexusOperationInboundInterceptor = &NexusOperationInboundInterceptorBase{}

// NexusOperationOutboundInterceptorBase is a default implementation of [NexusOperationOutboundInterceptor] that
// forwards calls to the next outbound interceptor.
//
// Note: Experimental
type NexusOperationOutboundInterceptorBase struct {
Next NexusOperationOutboundInterceptor
}

// GetClient implements NexusOperationOutboundInterceptor.
func (n *NexusOperationOutboundInterceptorBase) GetClient(ctx context.Context) Client {
return n.Next.GetClient(ctx)
}

// GetLogger implements NexusOperationOutboundInterceptor.
func (n *NexusOperationOutboundInterceptorBase) GetLogger(ctx context.Context) log.Logger {
return n.Next.GetLogger(ctx)
}

// GetMetricsHandler implements NexusOperationOutboundInterceptor.
func (n *NexusOperationOutboundInterceptorBase) GetMetricsHandler(ctx context.Context) metrics.Handler {
return n.Next.GetMetricsHandler(ctx)
}

// mustEmbedNexusOperationOutboundInterceptorBase implements NexusOperationOutboundInterceptor.
func (n *NexusOperationOutboundInterceptorBase) mustEmbedNexusOperationOutboundInterceptorBase() {}

var _ NexusOperationOutboundInterceptor = &NexusOperationOutboundInterceptorBase{}
Loading

0 comments on commit d32c252

Please sign in to comment.