/
clustertabcommands.go
58 lines (47 loc) · 1.35 KB
/
clustertabcommands.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
package clustertab
import (
"encoding/json"
"log"
"os/exec"
"time"
tea "github.com/charmbracelet/bubbletea"
"github.com/CLIP-HPC/SlurmCommander/internal/command"
"github.com/CLIP-HPC/SlurmCommander/internal/config"
)
var (
cc config.ConfigContainer
SinfoCmdSwitches = []string{"-a", "--json"}
)
func NewCmdCC(config config.ConfigContainer) {
cc = config
}
// Calls `sinfo` to get node information for Cluster Tab
func GetSinfo(t time.Time) tea.Msg {
var siJson SinfoJSON
cmd := cc.Binpaths["sinfo"]
out, err := exec.Command(cmd, SinfoCmdSwitches...).CombinedOutput()
if err != nil {
return command.ErrorMsg{
From: "GetSinfo",
ErrHelp: "Failed to run sinfo command, check your scom.conf and set the correct paths there.",
OrigErr: err,
}
}
err = json.Unmarshal(out, &siJson)
if err != nil {
return command.ErrorMsg{
From: "GetSinfo",
ErrHelp: "sinfo JSON failed to parse, note your slurm version and open an issue with us here: https://github.com/CLIP-HPC/SlurmCommander/issues/new/choose",
OrigErr: err,
}
}
return siJson
}
func TimedGetSinfo(l *log.Logger) tea.Cmd {
l.Printf("TimedGetSinfo() start, tick: %d\n", cc.GetTick())
return tea.Tick(cc.GetTick()*time.Second, GetSinfo)
}
func QuickGetSinfo(l *log.Logger) tea.Cmd {
l.Printf("QuickGetSinfo() start")
return tea.Tick(0*time.Second, GetSinfo)
}