-
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 all 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,38 @@ func NewSyncOperation[I any, O any]( | |||||
} | ||||||
} | ||||||
|
||||||
// SignalWorkflowInput is the input to a NewSignalWorkflowOperation. | ||||||
type SignalWorkflowInput struct { | ||||||
WorkflowID string | ||||||
RunID string | ||||||
SignalName string | ||||||
Arg any | ||||||
Comment on lines
+98
to
+101
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 document all of the public API fields. |
||||||
} | ||||||
|
||||||
// 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[T any]( | ||||||
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
|
||||||
name string, | ||||||
getSignalInput func(context.Context, T, nexus.StartOperationOptions) SignalWorkflowInput, | ||||||
) nexus.Operation[T, nexus.NoValue] { | ||||||
return NewSyncOperation(name, func(ctx context.Context, c client.Client, in T, options nexus.StartOperationOptions) (nexus.NoValue, error) { | ||||||
signalInput := getSignalInput(ctx, in, options) | ||||||
|
||||||
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, signalInput.WorkflowID, signalInput.RunID, signalInput.SignalName, signalInput.Arg) | ||||||
}) | ||||||
} | ||||||
|
||||||
func (o *syncOperation[I, O]) Name() string { | ||||||
return o.name | ||||||
} | ||||||
|
@@ -360,8 +391,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 +423,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.
Please fix the docstring. It's not the input to the operation.