From 59fad138919ec27cd9aa1a3963ba467c1dfabed6 Mon Sep 17 00:00:00 2001 From: luziqi Date: Thu, 10 Aug 2023 18:18:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=AE=BE=E5=A4=87=E5=88=97=E8=A1=A8v2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crontask/monkey.go | 17 ++++++++++++++--- device/device_v2.go | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/crontask/monkey.go b/crontask/monkey.go index 4b3a4d5..7850440 100644 --- a/crontask/monkey.go +++ b/crontask/monkey.go @@ -89,18 +89,29 @@ func CheckMonkeyTasks() { // 判断运行中的任务的实际状态 db.Model(models.MonkeyTask{}).Where("status = ? AND is_del = 0", "RUNNING").Find(&list) - for _, v := range list { + for i, v := range list { if v.Platform == "adr" { // 如果无对应正在运行的容器,判断为【结束】或【异常停止】 if len(monkey.GetTaskFromDocker(v.Id)) == 0 { // 如果预期结束时间(任务开始时间+运行时间) < 当前时间,判断任务为运行正常结束 - if v.StartTime+v.RunTime < int(time.Now().Unix()) { - // list[i].Status = "FINISH" + if v.StartTime+v.RunTime+300 < int(time.Now().Unix()) { + list[i].Status = "FINISH" // db.Table(v.TableName()).Model(models.MonkeyTask{}).Where("id = ?", v.Id).Update("status", list[i].Status) + // db.Table(v.TableName()).Model(models.MonkeyTask{}).Where("id = ?", v.Id).Update("end_time", time.Now().Unix()) + // common.PushCorntaskLog("[autogo] 任务标记为FINISH, " + cast.ToString(v.Id)) // common.PushMonkeyResult(v) } else { common.PushCorntaskLog("任务状态似乎异常,task_id=" + cast.ToString(v.Id)) } + } else { + // 预期结束时间(任务开始时间+运行时间) < 当前时间,判断任务为运行正常结束 + if v.StartTime+v.RunTime+300 < int(time.Now().Unix()) { + list[i].Status = "FINISH" + db.Table(v.TableName()).Model(models.MonkeyTask{}).Where("id = ?", v.Id).Update("status", list[i].Status) + db.Table(v.TableName()).Model(models.MonkeyTask{}).Where("id = ?", v.Id).Update("end_time", time.Now().Unix()) + common.PushCorntaskLog("[autogo] 任务标记为FINISH, 但容器未退出, task_id=" + cast.ToString(v.Id)) + } + } } } diff --git a/device/device_v2.go b/device/device_v2.go index 1291f20..3cc4106 100644 --- a/device/device_v2.go +++ b/device/device_v2.go @@ -203,3 +203,38 @@ func GetDeviceByUdidV2(c *gin.Context) { rsp.Data = dv c.JSON(http.StatusOK, rsp.Success()) } + +// @Tags 设备相关 /api/device/v2/ +// @Summary 获取设备列表 +// @Description 获取设备列表,可选筛选系统平台 +// @accept x-www-form-urlencoded +// @Param pf query string true "系统平台,不传查全部" +// @Success 200 {object} models.Response "返回设备列表" +// @Router /api/device/v2/list [get] +func GetDevicesV2(c *gin.Context) { + rsp := controllers.NewResponse() + + pf := c.DefaultQuery("pf", "") + if pf != "" && pf != "adr" && pf != "ios" { + c.JSON(http.StatusOK, rsp.Error("pf error")) + return + } + + db, err := dbsql.GetConn(dbsql.DSN_qaoms()) + if err != nil { + c.JSON(http.StatusOK, rsp.Error(err.Error())) + return + } + defer dbsql.Close(db) + + var list []models.DeviceV2 + + if pf != "" { + db.Model(models.DeviceV2{}).Where("platform = ? AND is_del = 0", pf).Find(&list) + } else { + db.Model(models.DeviceV2{}).Where("is_del = 0").Find(&list) + } + + rsp.Data = list + c.JSON(http.StatusOK, rsp.Success()) +}