-
Notifications
You must be signed in to change notification settings - Fork 127
/
reprioritize.go
51 lines (43 loc) · 1.53 KB
/
reprioritize.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package cmd
import (
"fmt"
"strconv"
"github.com/spf13/cobra"
"github.com/armadaproject/armada/internal/armadactl"
)
func reprioritizeCmd() *cobra.Command {
a := armadactl.New()
cmd := &cobra.Command{
Use: "reprioritize <priority>",
Short: "Reprioritize jobs in Armada",
Long: `Change the priority of a single or multiple jobs by specifying either a job id or a combination of queue & job set.`,
Args: cobra.ExactArgs(1),
PreRunE: func(cmd *cobra.Command, args []string) error {
return initParams(cmd, a.Params)
},
RunE: func(cmd *cobra.Command, args []string) error {
priorityString := args[0]
priorityFactor, err := strconv.ParseFloat(priorityString, 64)
if err != nil {
return fmt.Errorf("error converting %s to float64: %s", priorityString, err)
}
jobId, err := cmd.Flags().GetString("jobId")
if err != nil {
return fmt.Errorf("error reading jobId: %s", err)
}
queueName, err := cmd.Flags().GetString("queue")
if err != nil {
return fmt.Errorf("error reading queueName: %s", err)
}
jobSetId, err := cmd.Flags().GetString("jobSet")
if err != nil {
return fmt.Errorf("error reading jobSet: %s", err)
}
return a.Reprioritize(jobId, queueName, jobSetId, priorityFactor)
},
}
cmd.Flags().String("jobId", "", "Job to reprioritize")
cmd.Flags().String("queue", "", "Queue including jobs to be reprioritized (requires job set to be specified)")
cmd.Flags().String("jobSet", "", "Job set including jobs to be reprioritized (requires queue to be specified)")
return cmd
}