Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions nexus-cancelation/handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ 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,
// For this example, use a business ID derived from the greeting input so repeated operations
// for the same name and language resolve to the same workflow.
ID: service.HelloWorkflowID(input),
// Task queue defaults to the task queue this operation is handled on.
}, nil
})
Expand Down
6 changes: 3 additions & 3 deletions nexus-context-propagation/handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ 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,
// For this example, use a business ID derived from the greeting input so repeated operations
// for the same name and language resolve to the same workflow.
ID: service.HelloWorkflowID(input),
// Task queue defaults to the task queue this operation is handled on.
}, nil
})
Expand Down
6 changes: 3 additions & 3 deletions nexus-multiple-arguments/handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ 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,
// For this example, use a business ID derived from the greeting input so repeated operations
// for the same name and language resolve to the same workflow.
ID: service.HelloWorkflowID(input),
},
HelloHandlerWorkflow,
input.Name,
Expand Down
4 changes: 2 additions & 2 deletions nexus/caller/workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ 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 the same business ID strategy as the production handler.
ID: service.HelloWorkflowID(input),
}, nil
})

Expand Down
6 changes: 3 additions & 3 deletions nexus/handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ 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,
// For this example, use a business ID derived from the greeting input so repeated operations
// for the same name and language resolve to the same workflow.
ID: service.HelloWorkflowID(input),
// Task queue defaults to the task queue this operation is handled on.
}, nil
})
Expand Down
13 changes: 12 additions & 1 deletion nexus/service/api.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
// @@@SNIPSTART samples-go-nexus-service
package service

import (
"fmt"
"strings"
)

const HelloServiceName = "my-hello-service"

// Echo operation
Expand Down Expand Up @@ -33,4 +38,10 @@ type HelloInput struct {
type HelloOutput struct {
Message string
}
// @@@SNIPEND

func HelloWorkflowID(input HelloInput) string {
name := strings.ToLower(strings.ReplaceAll(strings.TrimSpace(input.Name), " ", "-"))
return fmt.Sprintf("hello-%s-%s", input.Language, name)
}

// @@@SNIPEND
Loading