зеркало из https://github.com/golang/build.git
cmd/gomote: use doPing instead of direct InstanceAlive requests
Simplifies some code. For golang/go#53956. Change-Id: Ie5606fd87a45c4a978b2c1a6b3fb33df4f7013d9 Reviewed-on: https://go-review.googlesource.com/c/build/+/418784 Run-TryBot: Michael Knyszek <mknyszek@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Carlos Amedee <carlos@golang.org> Auto-Submit: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Родитель
e96dfe678d
Коммит
ef00ab53a0
|
@ -12,8 +12,6 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
|
||||
"golang.org/x/build/internal/gomote/protos"
|
||||
)
|
||||
|
||||
func group(args []string) error {
|
||||
|
@ -105,13 +103,9 @@ func addToGroup(args []string) error {
|
|||
fmt.Fprintln(os.Stderr, "No active group found. Use -group or GOMOTE_GROUP.")
|
||||
usage()
|
||||
}
|
||||
ctx := context.Background()
|
||||
for _, inst := range args {
|
||||
ctx := context.Background()
|
||||
client := gomoteServerClient(ctx)
|
||||
_, err := client.InstanceAlive(ctx, &protos.InstanceAliveRequest{
|
||||
GomoteId: inst,
|
||||
})
|
||||
if err != nil {
|
||||
if err := doPing(ctx, inst); err != nil {
|
||||
return fmt.Errorf("instance %q: %s", inst, statusFromError(err))
|
||||
}
|
||||
activeGroup.Instances = append(activeGroup.Instances, inst)
|
||||
|
@ -250,13 +244,10 @@ func loadGroupFromFile(fname string) (*groupData, error) {
|
|||
//
|
||||
// Otherwise, we can get into situations where we sometimes
|
||||
// don't have an accurate record.
|
||||
ctx := context.Background()
|
||||
newInstances := make([]string, 0, len(g.Instances))
|
||||
for _, inst := range g.Instances {
|
||||
ctx := context.Background()
|
||||
client := gomoteServerClient(ctx)
|
||||
_, err := client.InstanceAlive(ctx, &protos.InstanceAliveRequest{
|
||||
GomoteId: inst,
|
||||
})
|
||||
err := doPing(ctx, inst)
|
||||
if instanceDoesNotExist(err) {
|
||||
continue
|
||||
} else if err != nil {
|
||||
|
|
|
@ -145,18 +145,15 @@ func run(args []string) error {
|
|||
if fs.NArg() == 0 {
|
||||
fs.Usage()
|
||||
}
|
||||
// First check if the instance name refers to a live instance.
|
||||
ctx := context.Background()
|
||||
client := gomoteServerClient(ctx)
|
||||
_, err := client.InstanceAlive(ctx, &protos.InstanceAliveRequest{
|
||||
GomoteId: fs.Arg(0),
|
||||
})
|
||||
|
||||
var cmd string
|
||||
var cmdArgs []string
|
||||
var runSet []string
|
||||
if err != nil {
|
||||
// When there's no active group, this must be an instance name.
|
||||
// Given that we got an error, we should surface that.
|
||||
|
||||
// First check if the instance name refers to a live instance.
|
||||
ctx := context.Background()
|
||||
if err := doPing(ctx, fs.Arg(0)); instanceDoesNotExist(err) {
|
||||
// When there's no active group, this is just an error.
|
||||
if activeGroup == nil {
|
||||
return fmt.Errorf("instance %q: %s", fs.Arg(0), statusFromError(err))
|
||||
}
|
||||
|
@ -167,7 +164,7 @@ func run(args []string) error {
|
|||
}
|
||||
cmd = fs.Arg(0)
|
||||
cmdArgs = fs.Args()[1:]
|
||||
} else {
|
||||
} else if err == nil {
|
||||
runSet = append(runSet, fs.Arg(0))
|
||||
if fs.NArg() == 1 {
|
||||
fmt.Fprintln(os.Stderr, "missing command")
|
||||
|
@ -175,6 +172,8 @@ func run(args []string) error {
|
|||
}
|
||||
cmd = fs.Arg(1)
|
||||
cmdArgs = fs.Args()[2:]
|
||||
} else {
|
||||
return fmt.Errorf("checking instance %q: %v", fs.Arg(0), err)
|
||||
}
|
||||
|
||||
var pathOpt []string
|
||||
|
@ -188,6 +187,7 @@ func run(args []string) error {
|
|||
// This is useful even if we don't have multiple gomotes running, since
|
||||
// it's easy to accidentally lose the output.
|
||||
var outDir string
|
||||
var err error
|
||||
if collect {
|
||||
outDir, err = os.Getwd()
|
||||
if err != nil {
|
||||
|
|
Загрузка…
Ссылка в новой задаче