diff --git a/dao/cid.go b/dao/cid.go index 0d2555e..9d9ae7e 100644 --- a/dao/cid.go +++ b/dao/cid.go @@ -3,16 +3,19 @@ package dao import ( "fmt" "gorm.io/gorm" + "time" ) type CID struct { gorm.Model - Auth_id int `gorm:"column:auth_id"` - Name string `gorm:"column:name"` - Url string `gorm:"column:url"` - Time int `gorm:"column:time"` // 定时任务,单位秒,大于0表示定时任务 - Script string `gorm:"column:script"` - Token string `gorm:"column:token"` // 用于外部回调 + Auth_id int `gorm:"column:auth_id"` + 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"` // 用于外部回调 } type CIDRunLog struct { @@ -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 +} diff --git a/handler/cid.go b/handler/cid.go index 1d0aaec..4ea985a 100644 --- a/handler/cid.go +++ b/handler/cid.go @@ -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]