You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.2 KiB
Go

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package crontask
import (
"autogo/common"
"autogo/dbsql"
"autogo/models"
"autogo/monkey"
)
func CheckMonkeyTasks() {
db, err := dbsql.GetConn(dbsql.DSN)
if err != nil {
return
}
defer dbsql.Close(db)
var list []models.MonkeyTask
db.Model(models.MonkeyTask{}).Where("status = ? AND is_del = 0", "WAITTING").Find(&list)
for _, task := range list {
var device models.Device
db.Table("device").Model(models.Device{}).Where("project = ? AND status = ?", task.Project, "online").First(&device)
if device.ID < 1 {
// 没有空闲设备
continue
}
go monkey.RunAndroidMonkeyCmd(task, device.Udid)
common.PushCorntaskLog("执行Monkey任务" + task.Project + "-" + device.Udid)
}
db.Model(models.MonkeyTask{}).Where("status = ? AND is_del = 0", "RUNNING").Find(&list)
for _, task := range list {
var pids []models.MonkeyPid
db.Model(models.MonkeyPid{}).Where("task_id = ?", task.Id).Find(&pids)
if code := checkTaskPids(pids); code == 0 {
task.Status = "RUNNING"
} else if code == 1 {
task.Status = "FINISH"
db.Model(models.MonkeyTask{}).Where("id = ?", task.Id).Update("status", task.Status)
common.PushMonkeyResult(task)
}
}
}