mirror of
https://github.com/samuelncui/yatm.git
synced 2026-01-05 21:14:57 +00:00
feat: job list
This commit is contained in:
@@ -3,6 +3,7 @@ package executor
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
@@ -11,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func (e *Executor) logPath(jobID int64) (string, string) {
|
||||
return path.Join(e.workDirectory, "job-logs"), fmt.Sprintf("%d.log", jobID)
|
||||
return path.Join(e.paths.Work, "job-logs"), fmt.Sprintf("%d.log", jobID)
|
||||
}
|
||||
|
||||
func (e *Executor) newLogWriter(jobID int64) (*os.File, error) {
|
||||
@@ -41,6 +42,28 @@ func (e *Executor) NewLogReader(jobID int64) (*os.File, error) {
|
||||
return file, nil
|
||||
}
|
||||
|
||||
func runCmdWithReturn(logger *logrus.Logger, cmd *exec.Cmd) ([]byte, error) {
|
||||
out, err := os.CreateTemp("", "*.out")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("create cmd out fail, %w", err)
|
||||
}
|
||||
out.Chmod(fs.ModePerm)
|
||||
out.Close()
|
||||
defer os.Remove(out.Name())
|
||||
|
||||
cmd.Env = append(cmd.Env, fmt.Sprintf("OUT=%s", out.Name()))
|
||||
if err := runCmd(logger, cmd); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
buf, err := os.ReadFile(out.Name())
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("read cmd out fail, %w", err)
|
||||
}
|
||||
|
||||
return buf, nil
|
||||
}
|
||||
|
||||
func runCmd(logger *logrus.Logger, cmd *exec.Cmd) error {
|
||||
writer := logger.WriterLevel(logrus.InfoLevel)
|
||||
cmd.Stdout = writer
|
||||
@@ -50,7 +73,7 @@ func runCmd(logger *logrus.Logger, cmd *exec.Cmd) error {
|
||||
}
|
||||
|
||||
func (e *Executor) reportPath(barcode string) (string, string) {
|
||||
return path.Join(e.workDirectory, "write-reports"), fmt.Sprintf("%s.log", barcode)
|
||||
return path.Join(e.paths.Work, "write-reports"), fmt.Sprintf("%s.log", barcode)
|
||||
}
|
||||
|
||||
func (e *Executor) newReportWriter(barcode string) (*os.File, error) {
|
||||
|
||||
Reference in New Issue
Block a user