feat: job list

This commit is contained in:
Samuel N Cui
2023-08-29 18:02:57 +08:00
parent cda9244e8e
commit 852cf8212e
80 changed files with 6173 additions and 1854 deletions

View File

@@ -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) {