diff --git a/nexus-cancelation/caller/starter/main.go b/nexus-cancelation/caller/starter/main.go index af7915695..2194d061d 100644 --- a/nexus-cancelation/caller/starter/main.go +++ b/nexus-cancelation/caller/starter/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "log" "os" "time" @@ -25,7 +26,7 @@ func main() { defer c.Close() workflowOptions := client.StartWorkflowOptions{ - ID: "nexus_hello_caller_workflow_" + time.Now().Format("20060102150405"), + ID: fmt.Sprintf("nexus-cancelation-hello-caller-%s-%d", "Nexus", time.Now().UnixNano()), TaskQueue: caller.TaskQueue, } diff --git a/nexus-cancelation/caller/workflows.go b/nexus-cancelation/caller/workflows.go index 1af692246..78485f4ce 100644 --- a/nexus-cancelation/caller/workflows.go +++ b/nexus-cancelation/caller/workflows.go @@ -46,7 +46,7 @@ func HelloCallerWorkflow(ctx workflow.Context, name string) (string, error) { service.HelloOperationName, service.HelloInput{Name: name, Language: lang}, workflow.NexusOperationOptions{ - // Set the cancellation type to NexusOperationCancellationTypeWaitRequested. + // Set the cancellation type to NexusOperationCancellationTypeWaitRequested. // This means that the caller will wait for the cancellation request to be received by the handler before // proceeding with the cancellation. // diff --git a/nexus-cancelation/handler/app.go b/nexus-cancelation/handler/app.go index de2997702..8eb01be9b 100644 --- a/nexus-cancelation/handler/app.go +++ b/nexus-cancelation/handler/app.go @@ -1,10 +1,10 @@ package handler import ( - "context" - "fmt" - "math/rand/v2" - "time" + "context" + "fmt" + "math/rand/v2" + "time" "github.com/nexus-rpc/sdk-go/nexus" @@ -19,13 +19,17 @@ import ( // Use the NewWorkflowRunOperation constructor, which is the easiest way to expose a workflow as an operation. // See alternatives at https://pkg.go.dev/go.temporal.io/sdk/temporalnexus. var HelloOperation = temporalnexus.NewWorkflowRunOperation(service.HelloOperationName, HelloHandlerWorkflow, func(ctx context.Context, input service.HelloInput, options nexus.StartOperationOptions) (client.StartWorkflowOptions, error) { - return client.StartWorkflowOptions{ - // Workflow IDs should typically be business meaningful IDs and are used to dedupe workflow starts. - // For this example, we're using the request ID allocated by Temporal when the caller workflow schedules - // the operation, this ID is guaranteed to be stable across retries of this operation. - ID: options.RequestID, - // Task queue defaults to the task queue this operation is handled on. - }, nil + return client.StartWorkflowOptions{ + // Workflow IDs should typically be business meaningful IDs and are used to dedupe workflow starts. + // Use the operation input to build an identifier that correlates to the customer request. + ID: fmt.Sprintf( + "nexus-cancelation-hello-%s-%s-%d", + input.Language, + input.Name, + time.Now().UnixNano(), + ), + // Task queue defaults to the task queue this operation is handled on. + }, nil }) func HelloHandlerWorkflow(ctx workflow.Context, input service.HelloInput) (service.HelloOutput, error) { diff --git a/nexus-context-propagation/caller/starter/main.go b/nexus-context-propagation/caller/starter/main.go index 614451913..fcacac996 100644 --- a/nexus-context-propagation/caller/starter/main.go +++ b/nexus-context-propagation/caller/starter/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "log" "os" "time" @@ -28,7 +29,7 @@ func main() { defer c.Close() ctx := context.Background() workflowOptions := client.StartWorkflowOptions{ - ID: "nexus_hello_caller_workflow_" + time.Now().Format("20060102150405"), + ID: fmt.Sprintf("nexus-context-propagation-hello-caller-%s-%s-%d", "Nexus", service.ES, time.Now().UnixNano()), TaskQueue: caller.TaskQueue, } diff --git a/nexus-context-propagation/handler/app.go b/nexus-context-propagation/handler/app.go index af44b5159..9229a4282 100644 --- a/nexus-context-propagation/handler/app.go +++ b/nexus-context-propagation/handler/app.go @@ -3,6 +3,7 @@ package handler import ( "context" "fmt" + "time" "github.com/nexus-rpc/sdk-go/nexus" @@ -19,9 +20,13 @@ import ( var HelloOperation = temporalnexus.NewWorkflowRunOperation(service.HelloOperationName, HelloHandlerWorkflow, func(ctx context.Context, input service.HelloInput, options nexus.StartOperationOptions) (client.StartWorkflowOptions, error) { return client.StartWorkflowOptions{ // Workflow IDs should typically be business meaningful IDs and are used to dedupe workflow starts. - // For this example, we're using the request ID allocated by Temporal when the caller workflow schedules - // the operation, this ID is guaranteed to be stable across retries of this operation. - ID: options.RequestID, + // Use the operation input to build an identifier that correlates to the customer request. + ID: fmt.Sprintf( + "nexus-context-propagation-hello-handler-%s-%s-%d", + input.Language, + input.Name, + time.Now().UnixNano(), + ), // Task queue defaults to the task queue this operation is handled on. }, nil }) diff --git a/nexus-multiple-arguments/caller/starter/main.go b/nexus-multiple-arguments/caller/starter/main.go index ec9ccbcd1..2583c0df1 100644 --- a/nexus-multiple-arguments/caller/starter/main.go +++ b/nexus-multiple-arguments/caller/starter/main.go @@ -2,6 +2,7 @@ package main import ( "context" + "fmt" "log" "os" "time" @@ -24,7 +25,7 @@ func main() { defer c.Close() ctx := context.Background() workflowOptions := client.StartWorkflowOptions{ - ID: "nexus_hello_caller_workflow_" + time.Now().Format("20060102150405"), + ID: fmt.Sprintf("nexus-multiple-arguments-hello-caller-%s-%s-%d", "Nexus", service.ES, time.Now().UnixNano()), TaskQueue: caller.TaskQueue, } diff --git a/nexus-multiple-arguments/handler/app.go b/nexus-multiple-arguments/handler/app.go index e3935ec59..6c5179624 100644 --- a/nexus-multiple-arguments/handler/app.go +++ b/nexus-multiple-arguments/handler/app.go @@ -3,6 +3,7 @@ package handler import ( "context" "fmt" + "time" "github.com/nexus-rpc/sdk-go/nexus" @@ -24,9 +25,13 @@ var HelloOperation = temporalnexus.MustNewWorkflowRunOperationWithOptions(tempor options, client.StartWorkflowOptions{ // Workflow IDs should typically be business meaningful IDs and are used to dedupe workflow starts. - // For this example, we're using the request ID allocated by Temporal when the caller workflow schedules - // the operation, this ID is guaranteed to be stable across retries of this operation. - ID: options.RequestID, + // Use the operation input to build an identifier that correlates to the customer request. + ID: fmt.Sprintf( + "nexus-multiargs-hello-%s-%s-%d", + input.Language, + input.Name, + time.Now().UnixNano(), + ), }, HelloHandlerWorkflow, input.Name, diff --git a/nexus/caller/starter/main.go b/nexus/caller/starter/main.go index 1398f9aa8..6e27d41a3 100644 --- a/nexus/caller/starter/main.go +++ b/nexus/caller/starter/main.go @@ -3,6 +3,7 @@ package main import ( "context" + "fmt" "log" "os" "time" @@ -24,14 +25,20 @@ func main() { log.Fatalln("Unable to create client", err) } defer c.Close() - runWorkflow(c, caller.EchoCallerWorkflow, "Nexus Echo 👋") - runWorkflow(c, caller.HelloCallerWorkflow, "Nexus", service.ES) + runWorkflow(c, fmt.Sprintf("nexus-caller-echo-%d", time.Now().UnixNano()), caller.EchoCallerWorkflow, "Nexus Echo 👋") + runWorkflow( + c, + fmt.Sprintf("nexus-caller-hello-%s-%s-%d", "Nexus", service.EN, time.Now().UnixNano()), + caller.HelloCallerWorkflow, + "Nexus", + service.EN, + ) } -func runWorkflow(c client.Client, workflow interface{}, args ...interface{}) { +func runWorkflow(c client.Client, workflowID string, workflow interface{}, args ...interface{}) { ctx := context.Background() workflowOptions := client.StartWorkflowOptions{ - ID: "nexus_hello_caller_workflow_" + time.Now().Format("20060102150405"), + ID: workflowID, TaskQueue: caller.TaskQueue, } @@ -49,4 +56,5 @@ func runWorkflow(c client.Client, workflow interface{}, args ...interface{}) { } log.Println("Workflow result:", result) } -// @@@SNIPEND \ No newline at end of file + +// @@@SNIPEND diff --git a/nexus/caller/workflows_test.go b/nexus/caller/workflows_test.go index d4af45105..e44cf5366 100644 --- a/nexus/caller/workflows_test.go +++ b/nexus/caller/workflows_test.go @@ -2,7 +2,9 @@ package caller_test import ( "context" + "fmt" "testing" + "time" "github.com/nexus-rpc/sdk-go/nexus" "github.com/stretchr/testify/require" @@ -22,8 +24,13 @@ var EchoOperation = nexus.NewSyncOperation(service.EchoOperationName, func(ctx c var HelloOperation = temporalnexus.NewWorkflowRunOperation(service.HelloOperationName, FakeHelloHandlerWorkflow, func(ctx context.Context, input service.HelloInput, options nexus.StartOperationOptions) (client.StartWorkflowOptions, error) { return client.StartWorkflowOptions{ - // Do not use RequestID for production use cases. ID should be a meaninful business ID. - ID: options.RequestID, + // Use operation input to build a business meaningful workflow ID for testing purposes as well. + ID: fmt.Sprintf( + "nexus-test-hello-%s-%s-%d", + input.Language, + input.Name, + time.Now().UnixNano(), + ), }, nil }) diff --git a/nexus/handler/app.go b/nexus/handler/app.go index bc0d03911..2452e4c4f 100644 --- a/nexus/handler/app.go +++ b/nexus/handler/app.go @@ -4,6 +4,7 @@ package handler import ( "context" "fmt" + "time" "github.com/nexus-rpc/sdk-go/nexus" @@ -27,9 +28,13 @@ var EchoOperation = nexus.NewSyncOperation(service.EchoOperationName, func(ctx c var HelloOperation = temporalnexus.NewWorkflowRunOperation(service.HelloOperationName, HelloHandlerWorkflow, func(ctx context.Context, input service.HelloInput, options nexus.StartOperationOptions) (client.StartWorkflowOptions, error) { return client.StartWorkflowOptions{ // Workflow IDs should typically be business meaningful IDs and are used to dedupe workflow starts. - // For this example, we're using the request ID allocated by Temporal when the caller workflow schedules - // the operation, this ID is guaranteed to be stable across retries of this operation. - ID: options.RequestID, + // Use the operation input to build an identifier that correlates to the customer request. + ID: fmt.Sprintf( + "nexus-handler-hello-%s-%s-%d", + input.Language, + input.Name, + time.Now().UnixNano(), + ), // Task queue defaults to the task queue this operation is handled on. }, nil }) diff --git a/nexus/service/api.go b/nexus/service/api.go index 0b68cdb8a..5474af726 100644 --- a/nexus/service/api.go +++ b/nexus/service/api.go @@ -33,4 +33,5 @@ type HelloInput struct { type HelloOutput struct { Message string } -// @@@SNIPEND \ No newline at end of file + +// @@@SNIPEND