-
Notifications
You must be signed in to change notification settings - Fork 222
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
579cb12
Add Nexus SignalWorkflowOperation
pdoerner 5b4e609
request ID and links handling
pdoerner ae9269c
docs
pdoerner d1b085e
test
pdoerner 0988871
test timeout
pdoerner 4f59c0a
test
pdoerner 25a68c1
test timeout
pdoerner 853ba1c
cleanup
pdoerner 3d555a9
feedback
pdoerner 0d172b4
comments
pdoerner eb96fc7
Merge branch 'master' into nexus-signal-operation
pdoerner d467f7c
experimental
pdoerner 85aaeb6
Merge branch 'master' into nexus-signal-operation
pdoerner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,13 @@ func waitForCancelWorkflow(ctx workflow.Context, ownID string) (string, error) { | |
return "", workflow.Await(ctx, func() bool { return false }) | ||
} | ||
|
||
func waitForSignalWorkflow(ctx workflow.Context, _ string) (string, error) { | ||
ch := workflow.GetSignalChannel(ctx, "nexus-signal") | ||
var val string | ||
ch.Receive(ctx, &val) | ||
return val, ctx.Err() | ||
} | ||
|
||
var workflowOp = temporalnexus.NewWorkflowRunOperation( | ||
"workflow-op", | ||
waitForCancelWorkflow, | ||
|
@@ -371,6 +378,52 @@ func TestNexusSyncOperation(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestNexusSignalWorkflowOperation(t *testing.T) { | ||
pdoerner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
receiverID := "nexus-signal-receiver-" + uuid.NewString() | ||
op := temporalnexus.NewSignalWorkflowOperation[string]("signal-op", receiverID, "", "nexus-signal") | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
||
tc := newTestContext(t, ctx) | ||
|
||
w := worker.New(tc.client, tc.taskQueue, worker.Options{}) | ||
service := nexus.NewService("test") | ||
require.NoError(t, service.Register(op)) | ||
w.RegisterNexusService(service) | ||
w.RegisterWorkflow(waitForSignalWorkflow) | ||
require.NoError(t, w.Start()) | ||
t.Cleanup(w.Stop) | ||
|
||
run, err := tc.client.ExecuteWorkflow(ctx, client.StartWorkflowOptions{ | ||
ID: receiverID, | ||
TaskQueue: tc.taskQueue, | ||
}, waitForSignalWorkflow, "successful") | ||
require.NoError(t, err) | ||
|
||
nc := tc.newNexusClient(t, service.Name) | ||
|
||
result, err := nexus.ExecuteOperation(ctx, nc, op, "nexus", | ||
nexus.ExecuteOperationOptions{ | ||
RequestID: "test-request-id", | ||
Header: nexus.Header{"test": "ok"}, | ||
CallbackURL: "http://localhost/test", | ||
CallbackHeader: nexus.Header{"test": "ok"}, | ||
}) | ||
require.NoError(t, err) | ||
require.Nil(t, result) | ||
|
||
var out string | ||
require.NoError(t, run.Get(ctx, &out)) | ||
require.Equal(t, "nexus", out) | ||
|
||
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. Test the request ID and links are properly attached. |
||
require.EventuallyWithT(t, func(t *assert.CollectT) { | ||
tc.requireTimer(t, metrics.NexusTaskEndToEndLatency, service.Name, op.Name()) | ||
tc.requireTimer(t, metrics.NexusTaskScheduleToStartLatency, service.Name, op.Name()) | ||
tc.requireTimer(t, metrics.NexusTaskExecutionLatency, service.Name, op.Name()) | ||
}, time.Second*3, time.Millisecond*100) | ||
} | ||
|
||
func TestNexusWorkflowRunOperation(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
@@ -550,6 +603,55 @@ func TestSyncOperationFromWorkflow(t *testing.T) { | |
}) | ||
} | ||
|
||
func TestSignalOperationFromWorkflow(t *testing.T) { | ||
receiverID := "nexus-signal-receiver-" + uuid.NewString() | ||
op := temporalnexus.NewSignalWorkflowOperation[string]("signal-op", receiverID, "", "nexus-signal") | ||
|
||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
tc := newTestContext(t, ctx) | ||
|
||
senderWF := func(ctx workflow.Context) error { | ||
c := workflow.NewNexusClient(tc.endpoint, "test") | ||
fut := c.ExecuteOperation(ctx, op, "nexus", workflow.NexusOperationOptions{}) | ||
|
||
var exec workflow.NexusOperationExecution | ||
if err := fut.GetNexusOperationExecution().Get(ctx, &exec); err != nil { | ||
return fmt.Errorf("expected start to succeed: %w", err) | ||
} | ||
if exec.OperationID != "" { | ||
return fmt.Errorf("expected empty operation ID") | ||
} | ||
|
||
return fut.Get(ctx, nil) | ||
} | ||
|
||
w := worker.New(tc.client, tc.taskQueue, worker.Options{}) | ||
service := nexus.NewService("test") | ||
require.NoError(t, service.Register(op)) | ||
w.RegisterNexusService(service) | ||
w.RegisterWorkflow(waitForSignalWorkflow) | ||
w.RegisterWorkflow(senderWF) | ||
require.NoError(t, w.Start()) | ||
t.Cleanup(w.Stop) | ||
|
||
receiver, err := tc.client.ExecuteWorkflow(ctx, client.StartWorkflowOptions{ | ||
ID: receiverID, | ||
TaskQueue: tc.taskQueue, | ||
}, waitForSignalWorkflow, "successful") | ||
require.NoError(t, err) | ||
|
||
sender, err := tc.client.ExecuteWorkflow(ctx, client.StartWorkflowOptions{ | ||
TaskQueue: tc.taskQueue, | ||
}, senderWF) | ||
require.NoError(t, err) | ||
require.NoError(t, sender.Get(ctx, nil)) | ||
|
||
var out string | ||
require.NoError(t, receiver.Get(ctx, &out)) | ||
require.Equal(t, "nexus", out) | ||
} | ||
|
||
func TestAsyncOperationFromWorkflow(t *testing.T) { | ||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5) | ||
defer cancel() | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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).