对cid运行添加上次成功失败信息
This commit is contained in:
parent
0edba050c3
commit
106e27f457
25
dao/cid.go
25
dao/cid.go
|
|
@ -3,16 +3,19 @@ package dao
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type CID struct {
|
type CID struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
Auth_id int `gorm:"column:auth_id"`
|
Auth_id int `gorm:"column:auth_id"`
|
||||||
Name string `gorm:"column:name"`
|
Name string `gorm:"column:name"`
|
||||||
Url string `gorm:"column:url"`
|
Url string `gorm:"column:url"`
|
||||||
Time int `gorm:"column:time"` // 定时任务,单位秒,大于0表示定时任务
|
Time int `gorm:"column:time"` // 定时任务,单位秒,大于0表示定时任务
|
||||||
Script string `gorm:"column:script"`
|
LastSuccess time.Time `gorm:"column:last_success" json:"last_success"`
|
||||||
Token string `gorm:"column:token"` // 用于外部回调
|
LastFail time.Time `gorm:"column:last_fail" json:"last_fail"`
|
||||||
|
Script string `gorm:"column:script"`
|
||||||
|
Token string `gorm:"column:token"` // 用于外部回调
|
||||||
}
|
}
|
||||||
|
|
||||||
type CIDRunLog struct {
|
type CIDRunLog struct {
|
||||||
|
|
@ -121,3 +124,13 @@ func FindCIDByCID(id uint) CID {
|
||||||
DB.Where("id = ? ", id).First(&cid)
|
DB.Where("id = ? ", id).First(&cid)
|
||||||
return 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)
|
elapsed := time.Since(start)
|
||||||
//fmt.Println("bash content:", scriptContent)
|
//fmt.Println("bash content:", scriptContent)
|
||||||
dao.CreateRunLog(id, authID, scriptContent, out.String(), err3_info, elapsed.Seconds()) //添加执行日志
|
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()
|
proto.CID_RunningMutex.Lock()
|
||||||
user_running_list = proto.CID_Running_Map[authID]
|
user_running_list = proto.CID_Running_Map[authID]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue