-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (70 loc) · 2.5 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"context"
"io"
"runtime"
"strings"
"time"
"github.com/alecthomas/kingpin"
sender "github.com/estafette/estafette-ci-cron-event-sender/services/sender"
manifest "github.com/estafette/estafette-ci-manifest"
foundation "github.com/estafette/estafette-foundation"
"github.com/opentracing/opentracing-go"
"github.com/rs/zerolog/log"
"github.com/uber/jaeger-client-go"
jaegercfg "github.com/uber/jaeger-client-go/config"
)
var (
appgroup string
app string
version string
branch string
revision string
buildDate string
goVersion = runtime.Version()
queueHosts = kingpin.Flag("queue-hosts", "The list of queue servers to publish to").Default("estafette-ci-queue-0.estafette-ci-queue").OverrideDefaultFromEnvar("QUEUE_HOSTS").String()
queueSubject = kingpin.Flag("queue-subject", "The queue subject name to publish to").Default("event.cron").OverrideDefaultFromEnvar("QUEUE_SUBJECT").String()
)
func main() {
// parse command line parameters
kingpin.Parse()
// init log format from envvar ESTAFETTE_LOG_FORMAT
foundation.InitLoggingFromEnv(foundation.NewApplicationInfo(appgroup, app, version, branch, revision, buildDate))
closer := initJaeger(app)
defer closer.Close()
ctx := context.Background()
span, ctx := opentracing.StartSpanFromContext(ctx, "Main")
defer span.Finish()
senderService, err := sender.NewService()
if err != nil {
log.Fatal().Err(err).Msg("Failed creating sender.Service")
}
err = senderService.CreateConnection(ctx, strings.Split(*queueHosts, ","))
if err != nil {
log.Fatal().Err(err).Msg("Failed creating connection to nats")
}
defer senderService.CloseConnection(ctx)
err = senderService.Publish(ctx, *queueSubject, manifest.EstafetteCronEvent{Time: time.Now().UTC()})
if err != nil {
log.Fatal().Err(err).Msg("Failed publishing cron event")
}
}
func handleError(jaegerCloser io.Closer, err error, message string) {
if err != nil {
jaegerCloser.Close()
log.Fatal().Err(err).Msg(message)
}
}
// initJaeger returns an instance of Jaeger Tracer that can be configured with environment variables
// https://github.com/jaegertracing/jaeger-client-go#environment-variables
func initJaeger(service string) io.Closer {
cfg, err := jaegercfg.FromEnv()
if err != nil {
log.Fatal().Err(err).Msg("Generating Jaeger config from environment variables failed")
}
closer, err := cfg.InitGlobalTracer(service, jaegercfg.Logger(jaeger.StdLogger))
if err != nil {
log.Fatal().Err(err).Msg("Generating Jaeger tracer failed")
}
return closer
}