diff --git a/cmd/create.go b/cmd/create.go index c062c4c..fd95efc 100644 --- a/cmd/create.go +++ b/cmd/create.go @@ -21,13 +21,14 @@ import ( func init() { rootCmd.AddCommand(createCmd) + createCmd.Flags().BoolVarP(&monitor, "monitor", "m", false, "monitor the result after sending the command") } var createCmd = &cobra.Command{ Use: "create", Short: "Create an Aurora Job", Run: createJob, - Args: cobra.ExactArgs(1), + Args: cobra.RangeArgs(1, 2), } func createJob(cmd *cobra.Command, args []string) { @@ -46,14 +47,15 @@ func createJob(cmd *cobra.Command, args []string) { log.Fatal("unable to create Aurora job: ", err) } - if ok, monitorErr := client.MonitorInstances(auroraJob.JobKey(), - auroraJob.GetInstanceCount(), - 5, - 50); !ok || monitorErr != nil { - if err := client.KillJob(auroraJob.JobKey()); err != nil { - log.Fatal(monitorErr, err) + if monitor { + if ok, monitorErr := client.MonitorInstances(auroraJob.JobKey(), + auroraJob.GetInstanceCount(), + 5, + 50); !ok || monitorErr != nil { + if err := client.KillJob(auroraJob.JobKey()); err != nil { + log.Fatal(monitorErr, err) + } + log.Fatal(monitorErr) } - log.Fatal(monitorErr) } - } diff --git a/cmd/kill.go b/cmd/kill.go index 3c3542b..0eb46c1 100644 --- a/cmd/kill.go +++ b/cmd/kill.go @@ -30,6 +30,7 @@ func init() { killJobCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment") killJobCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role") killJobCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name") + killJobCmd.Flags().BoolVarP(&monitor, "monitor", "m", false, "monitor the result after sending the command") killJobCmd.MarkFlagRequired("environment") killJobCmd.MarkFlagRequired("role") killJobCmd.MarkFlagRequired("name") @@ -57,8 +58,9 @@ func killJob(cmd *cobra.Command, args []string) { if err != nil { log.Fatalln(err) } - - if ok, err := client.MonitorInstances(job.JobKey(), 0, 5, 50); !ok || err != nil { - log.Fatalln("Unable to kill all instances of job") + if monitor { + if ok, err := client.MonitorInstances(job.JobKey(), 0, 5, 50); !ok || err != nil { + log.Fatalln("Unable to kill all instances of job") + } } } diff --git a/cmd/root.go b/cmd/root.go index ad50772..671cd30 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -46,6 +46,7 @@ var count int64 var filename string var message = new(string) var updateID string +var monitor bool var log = logrus.New() const australisVer = "v0.22.0"