-
Notifications
You must be signed in to change notification settings - Fork 94
Expand file tree
/
Copy pathmain.go
More file actions
61 lines (45 loc) · 1.19 KB
/
Copy pathmain.go
File metadata and controls
61 lines (45 loc) · 1.19 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"context"
"flag"
"log"
"sync"
"sync/atomic"
"time"
"github.com/cschleiden/go-workflows/client"
"github.com/cschleiden/go-workflows/samples"
scale "github.com/cschleiden/go-workflows/samples/scale"
"github.com/google/uuid"
)
var tostart = flag.Int("count", 100, "Number of workflow instances to start")
var count int32
func main() {
ctx := context.Background()
b := samples.GetBackend("scale", false)
count = int32(*tostart)
// Start workflow via client
c := client.New(b)
wg := &sync.WaitGroup{}
now := time.Now()
for i := 0; i < *tostart; i++ {
wg.Add(1)
go startWorkflow(ctx, c, wg)
}
wg.Wait()
log.Println("Finished in", time.Since(now))
}
func startWorkflow(ctx context.Context, c *client.Client, wg *sync.WaitGroup) {
wf, err := c.CreateWorkflowInstance(ctx, client.WorkflowInstanceOptions{
InstanceID: uuid.NewString(),
}, scale.Workflow1, "Hello world "+uuid.NewString())
if err != nil {
panic("could not start workflow")
}
err = c.WaitForWorkflowInstance(ctx, wf, time.Second*30)
if err != nil {
log.Println("Received error while waiting for workflow", wf.InstanceID, err)
}
cn := atomic.AddInt32(&count, -1)
log.Print(cn)
wg.Done()
}