cmd/storj-sim: add -failfast
Fail all the processes immediately when one of the processes fails. This is to make it more obvious that one of them has failed. To disable failfast, use `-failfast=false`. Change-Id: I2bbedf12fb653e42739d00273aa9ae515d34eda6
This commit is contained in:
parent
1e44be2900
commit
b33d7a318e
@ -25,7 +25,8 @@ type Flags struct {
|
|||||||
StorageNodeCount int
|
StorageNodeCount int
|
||||||
Identities int
|
Identities int
|
||||||
|
|
||||||
IsDev bool
|
IsDev bool
|
||||||
|
FailFast bool
|
||||||
|
|
||||||
OnlyEnv bool // only do things necessary for loading env vars
|
OnlyEnv bool // only do things necessary for loading env vars
|
||||||
|
|
||||||
@ -65,6 +66,7 @@ func main() {
|
|||||||
|
|
||||||
rootCmd.PersistentFlags().BoolVarP(&printCommands, "print-commands", "x", false, "print commands as they are run")
|
rootCmd.PersistentFlags().BoolVarP(&printCommands, "print-commands", "x", false, "print commands as they are run")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&flags.IsDev, "dev", "", true, "use configuration values tuned for development")
|
rootCmd.PersistentFlags().BoolVarP(&flags.IsDev, "dev", "", true, "use configuration values tuned for development")
|
||||||
|
rootCmd.PersistentFlags().BoolVarP(&flags.FailFast, "failfast", "", true, "stop all processes when one of the processes fails")
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVarP(&flags.Postgres, "postgres", "", os.Getenv("STORJ_SIM_POSTGRES"), "connection string for postgres (defaults to STORJ_SIM_POSTGRES)")
|
rootCmd.PersistentFlags().StringVarP(&flags.Postgres, "postgres", "", os.Getenv("STORJ_SIM_POSTGRES"), "connection string for postgres (defaults to STORJ_SIM_POSTGRES)")
|
||||||
rootCmd.PersistentFlags().StringVarP(&flags.Redis, "redis", "", os.Getenv("STORJ_SIM_REDIS"), "connection string for redis e.g. 127.0.0.1:6379 (defaults to STORJ_SIM_REDIS)")
|
rootCmd.PersistentFlags().StringVarP(&flags.Redis, "redis", "", os.Getenv("STORJ_SIM_REDIS"), "connection string for redis e.g. 127.0.0.1:6379 (defaults to STORJ_SIM_REDIS)")
|
||||||
|
@ -169,8 +169,14 @@ func networkTest(flags *Flags, command string, args []string) error {
|
|||||||
|
|
||||||
ctx, cancel := NewCLIContext(context.Background())
|
ctx, cancel := NewCLIContext(context.Background())
|
||||||
|
|
||||||
var group errgroup.Group
|
var group *errgroup.Group
|
||||||
processes.Start(ctx, &group, "run")
|
if processes.FailFast {
|
||||||
|
group, ctx = errgroup.WithContext(ctx)
|
||||||
|
} else {
|
||||||
|
group = &errgroup.Group{}
|
||||||
|
}
|
||||||
|
|
||||||
|
processes.Start(ctx, group, "run")
|
||||||
|
|
||||||
for _, process := range processes.List {
|
for _, process := range processes.List {
|
||||||
process.Status.Started.Wait(ctx)
|
process.Status.Started.Wait(ctx)
|
||||||
@ -230,7 +236,7 @@ func newNetwork(flags *Flags) (*Processes, error) {
|
|||||||
return all
|
return all
|
||||||
}
|
}
|
||||||
|
|
||||||
processes := NewProcesses(flags.Directory)
|
processes := NewProcesses(flags.Directory, flags.FailFast)
|
||||||
|
|
||||||
var host = flags.Host
|
var host = flags.Host
|
||||||
versioncontrol := processes.New(Info{
|
versioncontrol := processes.New(Info{
|
||||||
@ -644,7 +650,7 @@ func newNetwork(flags *Flags) (*Processes, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func identitySetup(network *Processes) (*Processes, error) {
|
func identitySetup(network *Processes) (*Processes, error) {
|
||||||
processes := NewProcesses(network.Directory)
|
processes := NewProcesses(network.Directory, network.FailFast)
|
||||||
|
|
||||||
for _, process := range network.List {
|
for _, process := range network.List {
|
||||||
if process.Info.Executable == "gateway" || process.Info.Executable == "redis-server" {
|
if process.Info.Executable == "gateway" || process.Info.Executable == "redis-server" {
|
||||||
|
@ -29,25 +29,33 @@ type Processes struct {
|
|||||||
Directory string
|
Directory string
|
||||||
List []*Process
|
List []*Process
|
||||||
|
|
||||||
|
FailFast bool
|
||||||
MaxStartupWait time.Duration
|
MaxStartupWait time.Duration
|
||||||
}
|
}
|
||||||
|
|
||||||
const storjSimMaxLineLen = 10000
|
const storjSimMaxLineLen = 10000
|
||||||
|
|
||||||
// NewProcesses returns a group of processes.
|
// NewProcesses returns a group of processes.
|
||||||
func NewProcesses(dir string) *Processes {
|
func NewProcesses(dir string, failfast bool) *Processes {
|
||||||
return &Processes{
|
return &Processes{
|
||||||
Output: NewPrefixWriter("sim", storjSimMaxLineLen, os.Stdout),
|
Output: NewPrefixWriter("sim", storjSimMaxLineLen, os.Stdout),
|
||||||
Directory: dir,
|
Directory: dir,
|
||||||
List: nil,
|
List: nil,
|
||||||
|
|
||||||
|
FailFast: failfast,
|
||||||
MaxStartupWait: time.Minute,
|
MaxStartupWait: time.Minute,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Exec executes a command on all processes.
|
// Exec executes a command on all processes.
|
||||||
func (processes *Processes) Exec(ctx context.Context, command string) error {
|
func (processes *Processes) Exec(ctx context.Context, command string) error {
|
||||||
var group errgroup.Group
|
var group *errgroup.Group
|
||||||
processes.Start(ctx, &group, command)
|
if processes.FailFast {
|
||||||
|
group, ctx = errgroup.WithContext(ctx)
|
||||||
|
} else {
|
||||||
|
group = &errgroup.Group{}
|
||||||
|
}
|
||||||
|
processes.Start(ctx, group, command)
|
||||||
return group.Wait()
|
return group.Wait()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user