对cid运行添加上次成功失败信息
This commit is contained in:
parent
0edba050c3
commit
106e27f457
13
dao/cid.go
13
dao/cid.go
|
|
@ -3,6 +3,7 @@ package dao
|
|||
import (
|
||||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
)
|
||||
|
||||
type CID struct {
|
||||
|
|
@ -11,6 +12,8 @@ type CID struct {
|
|||
Name string `gorm:"column:name"`
|
||||
Url string `gorm:"column:url"`
|
||||
Time int `gorm:"column:time"` // 定时任务,单位秒,大于0表示定时任务
|
||||
LastSuccess time.Time `gorm:"column:last_success" json:"last_success"`
|
||||
LastFail time.Time `gorm:"column:last_fail" json:"last_fail"`
|
||||
Script string `gorm:"column:script"`
|
||||
Token string `gorm:"column:token"` // 用于外部回调
|
||||
}
|
||||
|
|
@ -121,3 +124,13 @@ func FindCIDByCID(id uint) CID {
|
|||
DB.Where("id = ? ", id).First(&cid)
|
||||
return cid
|
||||
}
|
||||
|
||||
func UpdateLastSuccessByID(id int, time time.Time) error {
|
||||
res := DB.Where("id = ?", id).Update("last_success", time)
|
||||
return res.Error
|
||||
}
|
||||
|
||||
func UpdateLastFailByID(id int, time time.Time) error {
|
||||
res := DB.Where("id = ?", id).Update("last_fail", time)
|
||||
return res.Error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -310,6 +310,11 @@ echo "end"`
|
|||
elapsed := time.Since(start)
|
||||
//fmt.Println("bash content:", scriptContent)
|
||||
dao.CreateRunLog(id, authID, scriptContent, out.String(), err3_info, elapsed.Seconds()) //添加执行日志
|
||||
if err3 != nil {
|
||||
dao.UpdateLastFailByID(id, time.Now())
|
||||
} else {
|
||||
dao.UpdateLastSuccessByID(id, time.Now())
|
||||
}
|
||||
//移除正在运行
|
||||
proto.CID_RunningMutex.Lock()
|
||||
user_running_list = proto.CID_Running_Map[authID]
|
||||
|
|
|
|||
Loading…
Reference in New Issue