mirror of https://github.com/shunfei/cronsun
proc: 记录任务执行中信息接口
parent
54960acb40
commit
117d694b98
|
@ -1,6 +1,7 @@
|
|||
package models
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
|
@ -191,13 +192,30 @@ func (j *Job) Run() {
|
|||
}
|
||||
}
|
||||
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
j.Fail(t, fmt.Sprintf("%s\n\n%s", err.Error(), string(out)))
|
||||
var b bytes.Buffer
|
||||
cmd.Stdout = &b
|
||||
cmd.Stderr = &b
|
||||
if err := cmd.Start(); err != nil {
|
||||
j.Fail(t, fmt.Sprintf("%s", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
j.Success(t, string(out))
|
||||
p := &Process{
|
||||
ID: strconv.Itoa(cmd.Process.Pid),
|
||||
JobID: j.ID,
|
||||
NodeID: j.runOn,
|
||||
Time: t,
|
||||
}
|
||||
go p.Start()
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
p.Stop()
|
||||
j.Fail(t, fmt.Sprintf("%s", err.Error()))
|
||||
return
|
||||
}
|
||||
p.Stop()
|
||||
|
||||
j.Success(t, b.String())
|
||||
}
|
||||
|
||||
// 从 etcd 的 key 中取 id
|
||||
|
|
|
@ -52,3 +52,11 @@ func (p *Process) Put() error {
|
|||
_, err = DefalutClient.Put(p.Key(), p.Val(), client.WithLease(resp.ID))
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *Process) Start() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *Process) Stop() error {
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue