-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathapp.go
52 lines (45 loc) · 2.39 KB
/
app.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// @@@SNIPSTART samples-go-nexus-handler
package handler
import (
"context"
"fmt"
"github.com/nexus-rpc/sdk-go/nexus"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/temporalnexus"
"go.temporal.io/sdk/workflow"
"github.com/temporalio/samples-go/nexus/service"
)
// NewSyncOperation is a meant for exposing simple RPC handlers.
var EchoOperation = temporalnexus.NewSyncOperation(service.EchoOperationName, func(ctx context.Context, c client.Client, input service.EchoInput, options nexus.StartOperationOptions) (service.EchoOutput, error) {
// The method is provided with an SDK client that can be used for arbitrary calls such as signaling, querying,
// and listing workflows but implementations are free to make arbitrary calls to other services or databases, or
// perform simple computations such as this one.
return service.EchoOutput(input), nil
})
// 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
})
func HelloHandlerWorkflow(_ workflow.Context, input service.HelloInput) (service.HelloOutput, error) {
switch input.Language {
case service.EN:
return service.HelloOutput{Message: "Hello " + input.Name + " 👋"}, nil
case service.FR:
return service.HelloOutput{Message: "Bonjour " + input.Name + " 👋"}, nil
case service.DE:
return service.HelloOutput{Message: "Hallo " + input.Name + " 👋"}, nil
case service.ES:
return service.HelloOutput{Message: "¡Hola! " + input.Name + " 👋"}, nil
case service.TR:
return service.HelloOutput{Message: "Merhaba " + input.Name + " 👋"}, nil
}
return service.HelloOutput{}, fmt.Errorf("unsupported language %q", input.Language)
}
// @@@SNIPEND