Skip to content

Commit

Permalink
Merge pull request #14 from hv15/hist_config
Browse files Browse the repository at this point in the history
add history days and timeout params to config file
  • Loading branch information
pja237 authored Jan 4, 2023
2 parents b7abca5 + 1a11e11 commit 21cee5d
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 10 deletions.
11 changes: 11 additions & 0 deletions cmd/scom/scom.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@
#
#tick=3

# Job history tab view can show entries for number of days
# Default if unset = 7
# Min. value = 1
#histdays=7

# Job history tab command timeout (in seconds)
# The call to sacct can take a lot of time depending on the number of entries in the DB
# Default if unset = 30
# Min. value = 1
#histtimeout=30

# Paths to required slurm commands
# If some, or all of the following binaries reside in different directories,
# you can set their respective paths below:
Expand Down
15 changes: 8 additions & 7 deletions cmd/scom/scom.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,18 @@ func main() {

var (
debugSet bool = false
args *cmdline.CmdArgs
)

fmt.Printf("Welcome to Slurm Commander!\n\n")

args, err := cmdline.NewCmdArgs()
cc := config.NewConfigContainer()
err := cc.GetConfig()
if err != nil {
log.Printf("ERROR: parsing config files: %s\n", err)
}

args, err = cmdline.NewCmdArgs(cc.HistDays, cc.HistTimeout)
if err != nil {
log.Fatalf("ERROR: parsing cmdline args: %s\n", err)
}
Expand All @@ -43,12 +50,6 @@ func main() {
os.Exit(0)
}

cc := config.NewConfigContainer()
err = cc.GetConfig()
if err != nil {
log.Printf("ERROR: parsing config files: %s\n", err)
}

// TODO: JFT We have the CMDline switches and config, now overwrite/append what's changed
//log.Println(cc.DumpConfig())

Expand Down
6 changes: 3 additions & 3 deletions internal/cmdline/cmdline.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ type CmdArgs struct {
}

// NewCmdArgs return the CmdArgs structure built from command line parameters.
func NewCmdArgs() (*CmdArgs, error) {
func NewCmdArgs(d uint, t uint) (*CmdArgs, error) {
c := new(CmdArgs)

c.Version = flag.Bool("v", false, "Display version")
c.HistDays = flag.Uint("d", 7, "Jobs history fetch last N days")
c.HistTimeout = flag.Uint("t", 30, "Job history fetch timeout, seconds")
c.HistDays = flag.Uint("d", d, "Jobs history fetch last N days")
c.HistTimeout = flag.Uint("t", t, "Job history fetch timeout, seconds")
flag.Parse()
if !flag.Parsed() {
return nil, errors.New("failed to parse command line flags")
Expand Down
10 changes: 10 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type ConfigContainer struct {
Prefix string // if this is set, then we prepend this path to all commands
Binpaths map[string]string // else, we specify one by one
Tick uint
HistDays uint
HistTimeout uint
TemplateDirs []string
}

Expand Down Expand Up @@ -82,6 +84,14 @@ func (cc *ConfigContainer) GetConfig() error {
// set default Tick
cc.Tick = defaults.TickMin
}
// if unset (==0), set to default
if cc.HistDays < 1 {
cc.HistDays = defaults.HistDays
}
// if unset (==0), set to default
if cc.HistTimeout < 1 {
cc.HistTimeout = defaults.HistTimeout
}
cc.testNsetBinPaths()
cc.testNsetTemplateDirs()

Expand Down
2 changes: 2 additions & 0 deletions internal/defaults/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package defaults

const (
TickMin = 3 // minimal time in seconds between that can be set in config file. If not set or less then, Set to this value.
HistDays = 7
HistTimeout = 30

AppName = "scom"

Expand Down
1 change: 1 addition & 0 deletions internal/model/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ A special thank you goes to:
Seren Ümit
Kilian Cavalotti
Killian Murphy
Hans-Nikolai Vießmann
`

return s
Expand Down

0 comments on commit 21cee5d

Please sign in to comment.