From 2c833026beaffc4d969ec07f79f0128bfba3d222 Mon Sep 17 00:00:00 2001 From: ananaysingh <54039499+ananaysingh@users.noreply.github.com> Date: Thu, 18 Aug 2022 21:05:52 +0530 Subject: [PATCH] Updated killTask function to support multiple instances --- cmd/kill.go | 29 ++++++++++++++++++++++------- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/cmd/kill.go b/cmd/kill.go index 5f39814..8566a73 100644 --- a/cmd/kill.go +++ b/cmd/kill.go @@ -16,6 +16,7 @@ package cmd import ( "strconv" + "strings" realis "github.com/aurora-scheduler/gorealis/v2" "github.com/spf13/cobra" @@ -96,17 +97,31 @@ func killTask(cmd *cobra.Command, args []string) { //Check that instance number is passed if instance == nil { - log.Fatalln("instance number not found. Please pass a valid instance number.") + log.Fatalln("Instance number not found. Please pass a valid instance number. If you want to pass multiple instances, please pass them as space separated integer values") } - //Convert instance from string type to int32 type - instanceNumber, intErr := strconv.Atoi(*instance) - if intErr != nil { - log.Fatalln("Instance passed should be a number. Error: " + intErr.Error()) + /* + * In the following block, we convert instance numbers, which were passed as strings, to integer values + * After converting them to integers, we add them to a slice of type int32. + */ + var intErr error + var instanceNumber int + + splitString := strings.Split(*instance, " ") + instanceList := make([]int32, len(splitString)) + + for i := range instanceList { + instanceNumber, intErr = strconv.Atoi(splitString[i]) + if intErr != nil { + log.Fatalln("Instance passed should be a number. Error: " + intErr.Error()) + break + } else { + instanceList[i] = int32(instanceNumber) + } } - //Call the killtasks function - _, err := client.KillInstances(task.JobKey(), (int32)(instanceNumber)) + //Call the killtasks function, passing the instanceList as the list of instances to be killed. + _, err := client.KillInstances(task.JobKey(), instanceList...) if err != nil { log.Fatalln(err)