添加定时任务运行时间计算
This commit is contained in:
parent
395f1f681d
commit
9cf9876fb9
|
|
@ -20,6 +20,7 @@ type CIDRunLog struct {
|
|||
CID_id int `gorm:"column:cid_id"`
|
||||
Auth_id int `form:"column:auth_id"`
|
||||
Script string `gorm:"column:script"`
|
||||
RunTime float64 `gorm:"column:run_time"`
|
||||
Log string `gorm:"column:log"`
|
||||
Error string `gorm:"column:error"`
|
||||
}
|
||||
|
|
@ -75,8 +76,8 @@ func UpdateCIDByID(id, auth_id, time int, name, url, script, token string) bool
|
|||
}
|
||||
|
||||
// CreateRunLog,添加执行日志
|
||||
func CreateRunLog(cid_id, auth_id int, script, log, err string) uint {
|
||||
cidRunLog := CIDRunLog{CID_id: cid_id, Auth_id: auth_id, Log: log, Error: err, Script: script}
|
||||
func CreateRunLog(cid_id, auth_id int, script, log, err string, runtime float64) uint {
|
||||
cidRunLog := CIDRunLog{CID_id: cid_id, Auth_id: auth_id, Log: log, Error: err, Script: script, RunTime: runtime}
|
||||
result := DB.Create(&cidRunLog)
|
||||
if result != nil {
|
||||
fmt.Println(err)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import (
|
|||
"os/exec"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"videoplayer/dao"
|
||||
"videoplayer/proto"
|
||||
"videoplayer/worker"
|
||||
|
|
@ -221,6 +222,7 @@ func RunShell(username, url, script string, id, authID int) {
|
|||
echo "start"
|
||||
` + script + `
|
||||
echo "end"`
|
||||
start := time.Now()
|
||||
//执行脚本
|
||||
cmd := exec.Command("/bin/bash", "-c", scriptContent)
|
||||
// 使用bytes.Buffer捕获输出
|
||||
|
|
@ -231,8 +233,9 @@ echo "end"`
|
|||
if err3 != nil {
|
||||
err3_info = err3.Error()
|
||||
}
|
||||
elapsed := time.Since(start)
|
||||
//fmt.Println("bash content:", scriptContent)
|
||||
dao.CreateRunLog(id, authID, scriptContent, out.String(), err3_info) //添加执行日志
|
||||
dao.CreateRunLog(id, authID, scriptContent, out.String(), err3_info, elapsed.Seconds()) //添加执行日志
|
||||
}
|
||||
|
||||
// 定时任务处理逻辑
|
||||
|
|
|
|||
Loading…
Reference in New Issue