forked from vitessio/vitess
/
vtworkerclient.go
50 lines (43 loc) · 1.2 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
50
// 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"
"fmt"
"os"
"time"
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"
)
// The default values used by these flags cannot be taken from wrangler and
// actionnode modules, as we don't want to depend on them at all.
var (
actionTimeout = flag.Duration("action_timeout", time.Hour, "timeout for the total command")
server = flag.String("server", "", "server to use for connection")
)
func main() {
flag.Parse()
ctx, cancel := context.WithTimeout(context.Background(), *actionTimeout)
defer cancel()
err := vtworkerclient.RunCommandAndWait(
ctx, *server, flag.Args(),
func(e *logutil.LoggerEvent) {
switch e.Level {
case logutil.LOGGER_INFO:
log.Info(e.String())
case logutil.LOGGER_WARNING:
log.Warning(e.String())
case logutil.LOGGER_ERROR:
log.Error(e.String())
case logutil.LOGGER_CONSOLE:
fmt.Print(e.String())
}
})
if err != nil {
log.Error(err)
os.Exit(1)
}
}