Skip to content
Draft
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
3 changes: 2 additions & 1 deletion nexus-cancelation/caller/starter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"log"
"os"
"time"
Expand All @@ -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,
}

Expand Down
2 changes: 1 addition & 1 deletion nexus-cancelation/caller/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down
26 changes: 15 additions & 11 deletions nexus-cancelation/handler/app.go
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion nexus-context-propagation/caller/starter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"log"
"os"
"time"
Expand All @@ -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,
}

Expand Down
11 changes: 8 additions & 3 deletions nexus-context-propagation/handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"context"
"fmt"
"time"

"github.com/nexus-rpc/sdk-go/nexus"

Expand All @@ -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
})
Expand Down
3 changes: 2 additions & 1 deletion nexus-multiple-arguments/caller/starter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"context"
"fmt"
"log"
"os"
"time"
Expand All @@ -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,
}

Expand Down
11 changes: 8 additions & 3 deletions nexus-multiple-arguments/handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package handler
import (
"context"
"fmt"
"time"

"github.com/nexus-rpc/sdk-go/nexus"

Expand All @@ -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,
Expand Down
18 changes: 13 additions & 5 deletions nexus/caller/starter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main

import (
"context"
"fmt"
"log"
"os"
"time"
Expand All @@ -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,
}

Expand All @@ -49,4 +56,5 @@ func runWorkflow(c client.Client, workflow interface{}, args ...interface{}) {
}
log.Println("Workflow result:", result)
}
// @@@SNIPEND

// @@@SNIPEND
11 changes: 9 additions & 2 deletions nexus/caller/workflows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package caller_test

import (
"context"
"fmt"
"testing"
"time"

"github.com/nexus-rpc/sdk-go/nexus"
"github.com/stretchr/testify/require"
Expand All @@ -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
})

Expand Down
11 changes: 8 additions & 3 deletions nexus/handler/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package handler
import (
"context"
"fmt"
"time"

"github.com/nexus-rpc/sdk-go/nexus"

Expand All @@ -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
})
Expand Down
3 changes: 2 additions & 1 deletion nexus/service/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ type HelloInput struct {
type HelloOutput struct {
Message string
}
// @@@SNIPEND

// @@@SNIPEND