forked from temporalio/samples-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (40 loc) · 1.36 KB
/
main.go
File metadata and controls
46 lines (40 loc) · 1.36 KB
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
package main
import (
"log"
"time"
"go.temporal.io/sdk/client"
"go.temporal.io/sdk/temporal"
"go.temporal.io/sdk/worker"
"go.temporal.io/sdk/workflow"
)
const (
taskQueue = "say-hello-task-queue"
workflowName = "say-hello-workflow"
activityName = "say-hello-activity"
)
// SayHelloWorkflow simply returns the result of the say-hello activity.
func SayHelloWorkflow(ctx workflow.Context, name string) (string, error) {
ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
// Give it only 5 seconds to schedule and run with no retries
ScheduleToCloseTimeout: 5 * time.Second,
RetryPolicy: &temporal.RetryPolicy{MaximumAttempts: 1},
})
var response string
err := workflow.ExecuteActivity(ctx, activityName, name).Get(ctx, &response)
return response, err
}
func main() {
// Create client to localhost on default namespace
c, err := client.NewClient(client.Options{})
if err != nil {
log.Fatalf("Failed creating client: %v", err)
}
defer c.Close()
// Run workflow-only worker that does not handle activities
w := worker.New(c, taskQueue, worker.Options{LocalActivityWorkerOnly: true})
w.RegisterWorkflowWithOptions(SayHelloWorkflow, workflow.RegisterOptions{Name: workflowName})
log.Printf("Starting worker (ctrl+c to exit)")
if err := w.Run(worker.InterruptCh()); err != nil {
log.Fatalf("Worker failed to start: %v", err)
}
}