Refactor the multi-host salt install page.
[arvados.git] / services / crunch-dispatch-slurm / slurm.go
index bd193778b38c2172b13987945cfd2df1c58e22ce..e59826f763dcd45f7b6b9b150327b22e64332bb9 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: AGPL-3.0
 
-package main
+package dispatchslurm
 
 import (
        "fmt"
@@ -13,13 +13,22 @@ import (
 )
 
 type Slurm interface {
+       Batch(script io.Reader, args []string) error
        Cancel(name string) error
-       Renice(name string, nice int) error
        QueueCommand(args []string) *exec.Cmd
-       Batch(script io.Reader, args []string) error
+       Release(name string) error
+       Renice(name string, nice int64) error
+}
+
+type slurmCLI struct {
+       runSemaphore chan bool
 }
 
-type slurmCLI struct{}
+func NewSlurmCLI() *slurmCLI {
+       return &slurmCLI{
+               runSemaphore: make(chan bool, 3),
+       }
+}
 
 func (scli *slurmCLI) Batch(script io.Reader, args []string) error {
        return scli.run(script, "sbatch", args)
@@ -54,11 +63,17 @@ func (scli *slurmCLI) QueueCommand(args []string) *exec.Cmd {
        return exec.Command("squeue", args...)
 }
 
-func (scli *slurmCLI) Renice(name string, nice int) error {
+func (scli *slurmCLI) Release(name string) error {
+       return scli.run(nil, "scontrol", []string{"release", "Name=" + name})
+}
+
+func (scli *slurmCLI) Renice(name string, nice int64) error {
        return scli.run(nil, "scontrol", []string{"update", "JobName=" + name, fmt.Sprintf("Nice=%d", nice)})
 }
 
 func (scli *slurmCLI) run(stdin io.Reader, prog string, args []string) error {
+       scli.runSemaphore <- true
+       defer func() { <-scli.runSemaphore }()
        cmd := exec.Command(prog, args...)
        cmd.Stdin = stdin
        out, err := cmd.CombinedOutput()