-
Notifications
You must be signed in to change notification settings - Fork 220
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
Add Nexus SignalWorkflowOperation #1770
base: master
Are you sure you want to change the base?
Changes from 6 commits
579cb12
5b4e609
ae9269c
d1b085e
0988871
4f59c0a
25a68c1
853ba1c
3d555a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -45,7 +45,6 @@ import ( | |||||
"github.com/nexus-rpc/sdk-go/nexus" | ||||||
"go.temporal.io/api/common/v1" | ||||||
"go.temporal.io/api/enums/v1" | ||||||
|
||||||
"go.temporal.io/sdk/client" | ||||||
"go.temporal.io/sdk/internal" | ||||||
"go.temporal.io/sdk/internal/common/metrics" | ||||||
|
@@ -94,6 +93,28 @@ func NewSyncOperation[I any, O any]( | |||||
} | ||||||
} | ||||||
|
||||||
// SignalWorkflowInput is the input to a NewSignalWorkflowOperation. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please fix the docstring. It's not the input to the operation. |
||||||
type SignalWorkflowInput = internal.ClientSignalWorkflowInput | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't reuse the type from the interceptors, you want a type that contains the workflow ID, optional run ID and signal name. |
||||||
|
||||||
// NewSignalWorkflowOperation is a helper for creating a synchronous nexus.Operation to deliver a signal. | ||||||
// | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also call out that this ensures idempotency via the request ID mechanism (to some degree - violated if the workflow spans multiple runs) and the bidi linking is also important to call out (for now it's only uni-directional but we'll fix that). |
||||||
// NOTE: Experimental | ||||||
func NewSignalWorkflowOperation(name string) nexus.Operation[SignalWorkflowInput, nexus.NoValue] { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So why require users to pass in a function to extract the required parameters from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The caller doesn't care that this is a signal, that's the handler's call. |
||||||
return NewSyncOperation(name, func(ctx context.Context, c client.Client, in SignalWorkflowInput, options nexus.StartOperationOptions) (nexus.NoValue, error) { | ||||||
if options.RequestID != "" { | ||||||
ctx = context.WithValue(ctx, internal.NexusOperationRequestIDKey, options.RequestID) | ||||||
} | ||||||
|
||||||
links, err := convertNexusLinks(options.Links, GetLogger(ctx)) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
ctx = context.WithValue(ctx, internal.NexusOperationLinksKey, links) | ||||||
|
||||||
return nil, c.SignalWorkflow(ctx, in.WorkflowID, in.RunID, in.SignalName, in.Arg) | ||||||
}) | ||||||
} | ||||||
|
||||||
func (o *syncOperation[I, O]) Name() string { | ||||||
return o.name | ||||||
} | ||||||
|
@@ -360,8 +381,26 @@ func ExecuteUntypedWorkflow[R any]( | |||||
}) | ||||||
} | ||||||
|
||||||
links, err := convertNexusLinks(nexusOptions.Links, nctx.Log) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
internal.SetLinksOnStartWorkflowOptions(&startWorkflowOptions, links) | ||||||
|
||||||
run, err := nctx.Client.ExecuteWorkflow(ctx, startWorkflowOptions, workflowType, args...) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
return workflowHandle[R]{ | ||||||
namespace: nctx.Namespace, | ||||||
id: run.GetID(), | ||||||
runID: run.GetRunID(), | ||||||
}, nil | ||||||
} | ||||||
|
||||||
func convertNexusLinks(nexusLinks []nexus.Link, log log.Logger) ([]*common.Link, error) { | ||||||
var links []*common.Link | ||||||
for _, nexusLink := range nexusOptions.Links { | ||||||
for _, nexusLink := range nexusLinks { | ||||||
switch nexusLink.Type { | ||||||
case string((&common.Link_WorkflowEvent{}).ProtoReflect().Descriptor().FullName()): | ||||||
link, err := ConvertNexusLinkToLinkWorkflowEvent(nexusLink) | ||||||
|
@@ -374,18 +413,8 @@ func ExecuteUntypedWorkflow[R any]( | |||||
}, | ||||||
}) | ||||||
default: | ||||||
nctx.Log.Warn("ignoring unsupported link data type: %q", nexusLink.Type) | ||||||
log.Warn("ignoring unsupported link data type: %q", nexusLink.Type) | ||||||
} | ||||||
} | ||||||
internal.SetLinksOnStartWorkflowOptions(&startWorkflowOptions, links) | ||||||
|
||||||
run, err := nctx.Client.ExecuteWorkflow(ctx, startWorkflowOptions, workflowType, args...) | ||||||
if err != nil { | ||||||
return nil, err | ||||||
} | ||||||
return workflowHandle[R]{ | ||||||
namespace: nctx.Namespace, | ||||||
id: run.GetID(), | ||||||
runID: run.GetRunID(), | ||||||
}, nil | ||||||
return links, nil | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... how did this happen? @Quinn-With-Two-Ns looks like this is the third time this got repeated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally aliased
temporalnexus.SignalWorkflowInput
to this type and added it to the comment but then undid that and aliased it to theinternal
type. The automated tools complained about the checks until I ran with-fix
which I guess just added another line again.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just went ahead and manually removed all the duplicates
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@yuandrew FYI might be a bug in your alias tool