-
Notifications
You must be signed in to change notification settings - Fork 3
/
ps.go
66 lines (53 loc) · 1.46 KB
/
ps.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package cmd
// This file contains all the ps-related commands when starting `cedana ps ...`
import (
"fmt"
"os"
"strconv"
"github.com/cedana/cedana/api/services"
"github.com/cedana/cedana/api/services/task"
"github.com/olekukonko/tablewriter"
"github.com/rs/zerolog"
"github.com/spf13/cobra"
)
var psCmd = &cobra.Command{
Use: "ps",
Short: "List managed processes",
Run: func(cmd *cobra.Command, args []string) {
ctx := cmd.Context()
logger := ctx.Value("logger").(*zerolog.Logger)
cts, err := services.NewClient()
if err != nil {
logger.Error().Err(err).Msg("error creating client")
return
}
defer cts.Close()
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Job ID", "PID", "Status", "Checkpoint"})
resp, err := cts.Query(ctx, &task.QueryArgs{}) // get all processes
if err != nil {
logger.Error().Err(err).Msgf("error querying processes")
return
}
if len(resp.Processes) == 0 {
fmt.Println("No managed processes")
return
}
for _, v := range resp.Processes {
var checkpoint, status string
if v.RemoteState != nil {
// For now just grab latest checkpoint
checkpoint = fmt.Sprintf("%s (remote)", v.RemoteState[len(v.RemoteState)-1].CheckpointID)
} else {
checkpoint = v.CheckpointPath
}
status = v.JobState.String()
pid := strconv.Itoa(int(v.PID))
table.Append([]string{v.JID, pid, status, checkpoint})
}
table.Render()
},
}
func init() {
rootCmd.AddCommand(psCmd)
}