-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.go
71 lines (61 loc) · 1.49 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"context"
"os"
"time"
redis "github.com/redis/go-redis/v9"
"goa.design/clue/log"
"goa.design/pulse/pool"
"goa.design/pulse/pulse"
)
func main() {
// Setup Redis connection
rdb := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: os.Getenv("REDIS_PASSWORD"),
})
// Setup clue logger.
ctx := log.Context(context.Background())
log.FlushAndDisableBuffering(ctx)
var logger pulse.Logger
if len(os.Args) > 1 && os.Args[1] == "-v" {
logger = pulse.ClueLogger(ctx)
}
// Create client for worker pool "example"
client, err := pool.AddNode(ctx, "example", rdb,
pool.WithClientOnly(),
pool.WithLogger(logger),
)
if err != nil {
panic(err)
}
// Start 2 jobs
log.Infof(ctx, "starting job one")
if err := client.DispatchJob(ctx, "alpha", nil); err != nil {
panic(err)
}
log.Infof(ctx, "starting job two")
if err := client.DispatchJob(ctx, "beta", nil); err != nil {
panic(err)
}
time.Sleep(200 * time.Millisecond) // emulate delay
// Stop job one
log.Infof(ctx, "stopping job one")
if err := client.StopJob(ctx, "alpha"); err != nil {
panic(err)
}
// Notify and then stop job two
log.Infof(ctx, "notifying job two worker")
if err := client.NotifyWorker(ctx, "beta", []byte("hello")); err != nil {
panic(err)
}
log.Infof(ctx, "stopping job two")
if err := client.StopJob(ctx, "beta"); err != nil {
panic(err)
}
// Cleanup client on exit.
log.Infof(ctx, "done")
if err := client.Close(ctx); err != nil {
panic(err)
}
}