-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit.go
43 lines (38 loc) · 849 Bytes
/
submit.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
package robin
import (
"fmt"
"os"
"os/exec"
)
const (
robinJobFilename = "robin.job"
)
func fileExists(filename string) bool {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false
}
return !info.IsDir()
}
func Submit(bs BatchSystem, name string) error {
var jobData []byte
var err error
// Check whether it's a plain job file
if fileExists(name) {
jobData, err = os.ReadFile(name)
if err != nil {
return fmt.Errorf("read job data file: %w", err)
}
} else {
// Ask robin.job executable to generate the job data
cmd := exec.Command("./"+robinJobFilename, name)
jobData, err = cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("exectute %s command: %w", robinJobFilename, err)
}
}
if err := bs.Submit(string(jobData)); err != nil {
return fmt.Errorf("submit: %w", err)
}
return nil
}