forked from temporalio/samples-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (40 loc) · 1.28 KB
/
main.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
package main
import (
"context"
"log"
"github.com/pborman/uuid"
"go.temporal.io/sdk/client"
"github.com/temporalio/samples-go/mutex"
)
func main() {
// The client is a heavyweight object that should be created once per process.
c, err := client.Dial(client.Options{
HostPort: client.DefaultHostPort,
})
if err != nil {
log.Fatalln("Unable to create client", err)
}
defer c.Close()
// This workflow ID can be user business logic identifier as well.
resourceID := uuid.New()
workflow1Options := client.StartWorkflowOptions{
ID: "SampleWorkflow1WithMutex_" + uuid.New(),
TaskQueue: "mutex",
}
workflow2Options := client.StartWorkflowOptions{
ID: "SampleWorkflow2WithMutex_" + uuid.New(),
TaskQueue: "mutex",
}
we, err := c.ExecuteWorkflow(context.Background(), workflow1Options, mutex.SampleWorkflowWithMutex, resourceID)
if err != nil {
log.Fatalln("Unable to execute workflow1", err)
} else {
log.Println("Started workflow1", "WorkflowID", we.GetID(), "RunID", we.GetRunID())
}
we, err = c.ExecuteWorkflow(context.Background(), workflow2Options, mutex.SampleWorkflowWithMutex, resourceID)
if err != nil {
log.Fatalln("Unable to execute workflow2", err)
} else {
log.Println("Started workflow2", "WorkflowID", we.GetID(), "RunID", we.GetRunID())
}
}