-
Notifications
You must be signed in to change notification settings - Fork 27
/
sentry.go
76 lines (63 loc) · 1.35 KB
/
sentry.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
72
73
74
75
76
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"os/signal"
"github.com/getsentry/sentry-go"
"github.com/thoas/bokchoy"
bokchoysentry "github.com/thoas/bokchoy/contrib/sentry"
"github.com/thoas/bokchoy/middleware"
)
func main() {
var (
err error
ctx = context.Background()
run string
)
flag.StringVar(&run, "run", "", "service to run")
flag.Parse()
sentry.Init(sentry.ClientOptions{
Dsn: os.Getenv("SENTRY_DSN"),
})
engine, err := bokchoy.New(ctx, bokchoy.Config{
Broker: bokchoy.BrokerConfig{
Type: "redis",
Redis: bokchoy.RedisConfig{
Type: "client",
Client: bokchoy.RedisClientConfig{
Addr: "localhost:6379",
},
},
},
}, bokchoy.WithTracer(&bokchoysentry.SentryTracer{}))
if err != nil {
log.Fatal(err)
}
engine.Use(middleware.Recoverer)
switch run {
case "producer":
task, err := engine.Queue("tasks.message").Publish(ctx, map[string]string{
"data": "hello world",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(task, "has been published")
case "worker":
engine.Queue("tasks.message").HandleFunc(func(r *bokchoy.Request) error {
return fmt.Errorf("Unexpected error")
})
c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)
go func() {
for range c {
log.Print("Received signal, gracefully stopping")
engine.Stop(ctx)
}
}()
engine.Run(ctx)
}
}