Reviewed-on: https://git.openi.org.cn/OpenI/aiforge/pulls/3175 Reviewed-by: zouap <zouap@pcl.ac.cn>tags/v1.22.11.2^2
| @@ -2030,10 +2030,17 @@ func GetStoppedJobWithNoStartTimeEndTime() ([]*Cloudbrain, error) { | |||||
| cloudbrains := make([]*Cloudbrain, 0) | cloudbrains := make([]*Cloudbrain, 0) | ||||
| return cloudbrains, x.SQL("select * from cloudbrain where status in (?,?,?,?,?,?,?) and (start_time is null or end_time is null) limit 100", ModelArtsTrainJobCompleted, ModelArtsTrainJobFailed, ModelArtsTrainJobKilled, ModelArtsStopped, JobStopped, JobFailed, JobSucceeded).Find(&cloudbrains) | return cloudbrains, x.SQL("select * from cloudbrain where status in (?,?,?,?,?,?,?) and (start_time is null or end_time is null) limit 100", ModelArtsTrainJobCompleted, ModelArtsTrainJobFailed, ModelArtsTrainJobKilled, ModelArtsStopped, JobStopped, JobFailed, JobSucceeded).Find(&cloudbrains) | ||||
| } | } | ||||
| func GetC2NetWithAiCenterWrongJob() ([]*Cloudbrain, error) { | |||||
| cloudbrains := make([]*Cloudbrain, 0) | |||||
| return cloudbrains, x. | |||||
| In("status", ModelArtsTrainJobFailed, ModelArtsTrainJobKilled, ModelArtsStopped, JobStopped, JobFailed). | |||||
| Where("type = ?", TypeC2Net). | |||||
| Find(&cloudbrains) | |||||
| } | |||||
| func GetModelSafetyTestTask() ([]*Cloudbrain, error) { | func GetModelSafetyTestTask() ([]*Cloudbrain, error) { | ||||
| cloudbrains := make([]*Cloudbrain, 0) | cloudbrains := make([]*Cloudbrain, 0) | ||||
| sess := x.Where("job_type = ?", string(JobTypeModelSafety)) | |||||
| sess := x.Where("job_type=?", string(JobTypeModelSafety)) | |||||
| err := sess.Find(&cloudbrains) | err := sess.Find(&cloudbrains) | ||||
| return cloudbrains, err | return cloudbrains, err | ||||
| } | } | ||||
| @@ -6,9 +6,10 @@ | |||||
| package private | package private | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/routers/admin" | |||||
| "strings" | "strings" | ||||
| "code.gitea.io/gitea/routers/admin" | |||||
| "code.gitea.io/gitea/routers/repo" | "code.gitea.io/gitea/routers/repo" | ||||
| "code.gitea.io/gitea/modules/log" | "code.gitea.io/gitea/modules/log" | ||||
| @@ -52,6 +53,7 @@ func RegisterRoutes(m *macaron.Macaron) { | |||||
| m.Get("/tool/org_stat", OrgStatisticManually) | m.Get("/tool/org_stat", OrgStatisticManually) | ||||
| m.Post("/tool/update_repo_visit/:date", UpdateRepoVisit) | m.Post("/tool/update_repo_visit/:date", UpdateRepoVisit) | ||||
| m.Post("/task/history_handle/duration", repo.HandleTaskWithNoDuration) | m.Post("/task/history_handle/duration", repo.HandleTaskWithNoDuration) | ||||
| m.Post("/task/history_handle/aicenter", repo.HandleTaskWithAiCenter) | |||||
| m.Post("/resources/specification/handle_historical_task", admin.RefreshHistorySpec) | m.Post("/resources/specification/handle_historical_task", admin.RefreshHistorySpec) | ||||
| }, CheckInternalToken) | }, CheckInternalToken) | ||||
| @@ -2,7 +2,6 @@ package repo | |||||
| import ( | import ( | ||||
| "bufio" | "bufio" | ||||
| "code.gitea.io/gitea/modules/urfs_client/urchin" | |||||
| "encoding/json" | "encoding/json" | ||||
| "errors" | "errors" | ||||
| "fmt" | "fmt" | ||||
| @@ -16,6 +15,8 @@ import ( | |||||
| "time" | "time" | ||||
| "unicode/utf8" | "unicode/utf8" | ||||
| "code.gitea.io/gitea/modules/urfs_client/urchin" | |||||
| "code.gitea.io/gitea/modules/dataset" | "code.gitea.io/gitea/modules/dataset" | ||||
| "code.gitea.io/gitea/services/cloudbrain/cloudbrainTask" | "code.gitea.io/gitea/services/cloudbrain/cloudbrainTask" | ||||
| @@ -1,7 +1,6 @@ | |||||
| package repo | package repo | ||||
| import ( | import ( | ||||
| "code.gitea.io/gitea/modules/urfs_client/urchin" | |||||
| "encoding/json" | "encoding/json" | ||||
| "errors" | "errors" | ||||
| "fmt" | "fmt" | ||||
| @@ -13,6 +12,9 @@ import ( | |||||
| "strings" | "strings" | ||||
| "time" | "time" | ||||
| "code.gitea.io/gitea/modules/urfs_client/urchin" | |||||
| "code.gitea.io/gitea/routers/response" | |||||
| "code.gitea.io/gitea/services/cloudbrain/cloudbrainTask" | "code.gitea.io/gitea/services/cloudbrain/cloudbrainTask" | ||||
| "code.gitea.io/gitea/modules/dataset" | "code.gitea.io/gitea/modules/dataset" | ||||
| @@ -863,10 +865,10 @@ func GrampusTrainJobShow(ctx *context.Context) { | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| err = models.UpdateJob(task) | |||||
| if err != nil { | |||||
| log.Error("UpdateJob failed:" + err.Error()) | |||||
| } | |||||
| } | |||||
| err = models.UpdateJob(task) | |||||
| if err != nil { | |||||
| log.Error("UpdateJob failed:" + err.Error()) | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -1102,3 +1104,38 @@ func downloadZipCode(ctx *context.Context, codePath, branchName string) error { | |||||
| return nil | return nil | ||||
| } | } | ||||
| func HandleTaskWithAiCenter(ctx *context.Context) { | |||||
| log.Info("HandleTaskWithAiCenter start") | |||||
| updateCounts := 0 | |||||
| cloudBrains, err := models.GetC2NetWithAiCenterWrongJob() | |||||
| if err != nil { | |||||
| log.Error("GetC2NetWithAiCenterWrongJob failed:" + err.Error()) | |||||
| return | |||||
| } | |||||
| if len(cloudBrains) == 0 { | |||||
| log.Info("HandleC2NetWithAiCenterWrongJob:no task need handle") | |||||
| return | |||||
| } | |||||
| cloudBrainCounts := len(cloudBrains) | |||||
| for _, task := range cloudBrains { | |||||
| result, err := grampus.GetJob(task.JobID) | |||||
| if err != nil { | |||||
| log.Error("GetJob failed:" + err.Error()) | |||||
| continue | |||||
| } | |||||
| if result != nil { | |||||
| if len(result.JobInfo.Tasks[0].CenterID) == 1 && len(result.JobInfo.Tasks[0].CenterName) == 1 { | |||||
| task.AiCenter = result.JobInfo.Tasks[0].CenterID[0] + "+" + result.JobInfo.Tasks[0].CenterName[0] | |||||
| } | |||||
| err = models.UpdateJob(task) | |||||
| if err != nil { | |||||
| log.Error("UpdateJob failed:" + err.Error()) | |||||
| } | |||||
| updateCounts++ | |||||
| } | |||||
| } | |||||
| r := make(map[string]interface{}, 0) | |||||
| r["cloudBrainCounts"] = cloudBrainCounts | |||||
| r["updateCounts"] = updateCounts | |||||
| ctx.JSON(http.StatusOK, response.SuccessWithData(r)) | |||||
| } | |||||