skip monitoring create/kill jobs (#13)

Added flag -m and --monitor that can be set in order to monitor a job creation or a job kill. By default monitor is set to true.
This commit is contained in:
lenhattan86 2020-09-30 16:32:53 -07:00 committed by GitHub
parent 82fe22e013
commit 5efbbce6c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 12 deletions

View file

@ -21,13 +21,14 @@ import (
func init() { func init() {
rootCmd.AddCommand(createCmd) rootCmd.AddCommand(createCmd)
createCmd.Flags().BoolVarP(&monitor, "monitor", "m", false, "monitor the result after sending the command")
} }
var createCmd = &cobra.Command{ var createCmd = &cobra.Command{
Use: "create", Use: "create",
Short: "Create an Aurora Job", Short: "Create an Aurora Job",
Run: createJob, Run: createJob,
Args: cobra.ExactArgs(1), Args: cobra.RangeArgs(1, 2),
} }
func createJob(cmd *cobra.Command, args []string) { func createJob(cmd *cobra.Command, args []string) {
@ -46,6 +47,7 @@ func createJob(cmd *cobra.Command, args []string) {
log.Fatal("unable to create Aurora job: ", err) log.Fatal("unable to create Aurora job: ", err)
} }
if monitor {
if ok, monitorErr := client.MonitorInstances(auroraJob.JobKey(), if ok, monitorErr := client.MonitorInstances(auroraJob.JobKey(),
auroraJob.GetInstanceCount(), auroraJob.GetInstanceCount(),
5, 5,
@ -55,5 +57,5 @@ func createJob(cmd *cobra.Command, args []string) {
} }
log.Fatal(monitorErr) log.Fatal(monitorErr)
} }
}
} }

View file

@ -30,6 +30,7 @@ func init() {
killJobCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment") killJobCmd.Flags().StringVarP(env, "environment", "e", "", "Aurora Environment")
killJobCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role") killJobCmd.Flags().StringVarP(role, "role", "r", "", "Aurora Role")
killJobCmd.Flags().StringVarP(name, "name", "n", "", "Aurora Name") 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("environment")
killJobCmd.MarkFlagRequired("role") killJobCmd.MarkFlagRequired("role")
killJobCmd.MarkFlagRequired("name") killJobCmd.MarkFlagRequired("name")
@ -57,8 +58,9 @@ func killJob(cmd *cobra.Command, args []string) {
if err != nil { if err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
if monitor {
if ok, err := client.MonitorInstances(job.JobKey(), 0, 5, 50); !ok || err != nil { if ok, err := client.MonitorInstances(job.JobKey(), 0, 5, 50); !ok || err != nil {
log.Fatalln("Unable to kill all instances of job") log.Fatalln("Unable to kill all instances of job")
} }
} }
}

View file

@ -46,6 +46,7 @@ var count int64
var filename string var filename string
var message = new(string) var message = new(string)
var updateID string var updateID string
var monitor bool
var log = logrus.New() var log = logrus.New()
const australisVer = "v0.22.0" const australisVer = "v0.22.0"