forked from vitessio/vitess
-
Notifications
You must be signed in to change notification settings - Fork 1
/
vtworkerclient.go
49 lines (40 loc) · 1.04 KB
/
vtworkerclient.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
// Copyright 2015, Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"flag"
"os"
"os/signal"
"syscall"
log "github.com/golang/glog"
"github.com/youtube/vitess/go/vt/logutil"
"github.com/youtube/vitess/go/vt/worker/vtworkerclient"
"golang.org/x/net/context"
logutilpb "github.com/youtube/vitess/go/vt/proto/logutil"
)
var (
server = flag.String("server", "", "server to use for connection")
)
func main() {
flag.Parse()
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGTERM, syscall.SIGINT)
go func() {
s := <-sigChan
log.Errorf("Trying to cancel current command after receiving signal: %v", s)
cancel()
}()
logger := logutil.NewConsoleLogger()
err := vtworkerclient.RunCommandAndWait(
ctx, *server, flag.Args(),
func(e *logutilpb.Event) {
logutil.LogEvent(logger, e)
})
if err != nil {
log.Error(err)
os.Exit(1)
}
}