添加cid执行成功失败时间更新
This commit is contained in:
parent
1573353f49
commit
0c5cb83f69
23
dao/cid.go
23
dao/cid.go
|
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"gorm.io/gorm"
|
||||
"time"
|
||||
"videoplayer/proto"
|
||||
)
|
||||
|
||||
type CID struct {
|
||||
|
|
@ -28,6 +29,28 @@ type CIDRunLog struct {
|
|||
Error string `gorm:"column:error"`
|
||||
}
|
||||
|
||||
func GetDB() *gorm.DB {
|
||||
var db *gorm.DB
|
||||
if proto.Config.SERVER_SQL_LOG {
|
||||
db = DB.Debug()
|
||||
} else {
|
||||
db = DB
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
func UpdateCIDLastSuccessTime(id int) error {
|
||||
db := GetDB()
|
||||
res := db.Exec("UPDATE SET last_success = now() where id = ?", id)
|
||||
return res.Error
|
||||
}
|
||||
|
||||
func UpdateCIDLastFailureTime(id int) error {
|
||||
db := GetDB()
|
||||
res := db.Exec("UPDATE SET last_fail = now() where id = ?", id)
|
||||
return res.Error
|
||||
}
|
||||
|
||||
// CreateCID 创建持续集成、部署
|
||||
func CreateCID(name, url, script, token string, time, auth_id int) uint {
|
||||
cid := CID{Name: name, Url: url, Script: script, Token: token, Auth_id: auth_id, Time: time}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"log"
|
||||
"net/http"
|
||||
"os/exec"
|
||||
"strconv"
|
||||
|
|
@ -306,6 +307,10 @@ echo "end"`
|
|||
err3_info := ""
|
||||
if err3 != nil {
|
||||
err3_info = err3.Error()
|
||||
err := dao.UpdateCIDLastFailureTime(id)
|
||||
if err != nil {
|
||||
log.Println("[ERROR] update cid:", id, " last fail time err:", err)
|
||||
}
|
||||
}
|
||||
elapsed := time.Since(start)
|
||||
//fmt.Println("bash content:", scriptContent)
|
||||
|
|
@ -325,6 +330,13 @@ echo "end"`
|
|||
break
|
||||
}
|
||||
}
|
||||
//更新运行成功时间
|
||||
err := dao.UpdateCIDLastSuccessTime(id)
|
||||
if err != nil {
|
||||
log.Println("[ERROR] update cid:", id, " last success time err:", err)
|
||||
return
|
||||
}
|
||||
|
||||
proto.CID_Running_Map[authID] = user_running_list
|
||||
proto.CID_RunningMutex.Unlock()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue