From 106e27f457870e03e0a9f88da60a31cffe062066 Mon Sep 17 00:00:00 2001 From: junleea <354425203@qq.com> Date: Sun, 28 Sep 2025 20:41:15 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9cid=E8=BF=90=E8=A1=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=B8=8A=E6=AC=A1=E6=88=90=E5=8A=9F=E5=A4=B1=E8=B4=A5?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dao/cid.go | 25 +++++++++++++++++++------ handler/cid.go | 5 +++++ 2 files changed, 24 insertions(+), 6 deletions(-) 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]