Skip to content

Commit

Permalink
feat: aerender报错
Browse files Browse the repository at this point in the history
  • Loading branch information
yearnfar committed Aug 14, 2020
1 parent e18cc54 commit c08d538
Showing 1 changed file with 40 additions and 8 deletions.
48 changes: 40 additions & 8 deletions internal/gexrender/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package gexrender
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"os"
"os/exec"
"path"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
Expand All @@ -33,6 +35,10 @@ type Job struct {

}

var renderTimeRegex = regexp.MustCompile(`PROGRESS: Total Time Elapsed: (\d+) Seconds`)
var renderErrorRegex = regexp.MustCompile(`Error: gexrender:(.*)`)
var aeErrorRegex = regexp.MustCompile(`aerender ERROR:(.*)`)

// CreateJob 创建任务
func CreateJob(setting *Setting) (job *Job, err error) {
var data []byte
Expand Down Expand Up @@ -215,13 +221,6 @@ func (j *Job) Render() (err error) {
cmd.Stdout = &stdout
err = cmd.Run()

if err != nil && j.Setting.StopOnError {
log.Errorf("[%s]Error starting aerender process:: %v", j.Uid, err)
return
}

log.Infof(`[%s] rendering took ~%.1f sec.`, j.Uid, time.Since(startTime).Seconds())

var output []string
if stdout.Len() > 0 {
output = append(output, stdout.String())
Expand All @@ -233,7 +232,40 @@ func (j *Job) Render() (err error) {
outputStr := strings.Join(output, "")
logPath := filepath.Join(j.WorkPath, fmt.Sprintf(`../aerender-%s.log`, j.Uid))
_ = ioutil.WriteFile(logPath, []byte(outputStr), 0644)
return

if err != nil {
log.Errorf("[%s]Error starting aerender process:: %v", j.Uid, err)
}

if err != nil && j.Setting.StopOnError {
log.Errorf("[%s]stop on error!", j.Uid)
return
}

// 渲染成功
if strings.Contains(outputStr, "Finished composition") {
timeMatches := renderTimeRegex.FindStringSubmatch(outputStr)
if len(timeMatches) == 2 {
log.Infof(`[%s] rendering took ~%d sec.`, j.Uid, timeMatches[1])
} else {
log.Infof(`[%s] rendering took ~%.0f sec.`, j.Uid, time.Since(startTime).Seconds())
}
return
} else {
log.Infof(`[%s] rendering took ~%.0f sec.`, j.Uid, time.Since(startTime).Seconds())

errMatches := renderErrorRegex.FindStringSubmatch(outputStr)
if len(errMatches) > 0 {
return errors.New(strings.TrimSpace(errMatches[1]))
}

aeErrMatches := aeErrorRegex.FindStringSubmatch(outputStr)
if len(aeErrMatches) > 0 {
return errors.New(strings.TrimSpace(aeErrMatches[1]))
}

return errors.New("渲染失败")
}
}

func (j *Job) Parse(s string) {
Expand Down

0 comments on commit c08d538

Please sign in to comment.