-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
submit: Add robin.job submission functionality
- Loading branch information
Showing
2 changed files
with
46 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} |