@@ -205,7 +205,7 @@ type Cloudbrain struct { | |||
BenchmarkTypeRankLink string `xorm:"-"` | |||
StartTime timeutil.TimeStamp | |||
EndTime timeutil.TimeStamp | |||
Cleared bool `xorm:"DEFAULT false"` | |||
Cleared bool `xorm:"DEFAULT false"` | |||
Spec *Specification `xorm:"-"` | |||
} | |||
@@ -1988,7 +1988,7 @@ func GetCloudbrainByID(id string) (*Cloudbrain, error) { | |||
return getRepoCloudBrain(cb) | |||
} | |||
func IsCloudbrainExistByJobName(jobName string)(bool,error){ | |||
func IsCloudbrainExistByJobName(jobName string) (bool, error) { | |||
return x.Unscoped().Exist(&Cloudbrain{ | |||
JobName: jobName, | |||
}) | |||
@@ -2172,25 +2172,25 @@ func GetCloudBrainOneStoppedNotDebugJobDaysAgo(days int, limit int) ([]*Cloudbra | |||
Limit(limit). | |||
Find(&cloudbrains) | |||
} | |||
/** | |||
本方法考虑了再次调试的情况,多次调试取最后一次的任务的结束时间 | |||
*/ | |||
*/ | |||
func GetCloudBrainOneStoppedDebugJobDaysAgo(days int, limit int) ([]*Cloudbrain, error) { | |||
cloudbrains := make([]*Cloudbrain, 0, 10) | |||
endTimeBefore := time.Now().Unix() - int64(days)*24*3600 | |||
missEndTimeBefore := endTimeBefore - 24*3600 | |||
sql:=`SELECT id,job_name,job_id from (SELECT DISTINCT ON (job_name) | |||
sql := `SELECT id,job_name,job_id from (SELECT DISTINCT ON (job_name) | |||
id, job_name, job_id,status,end_time,updated_unix,cleared | |||
FROM cloudbrain | |||
where type=0 and job_type='DEBUG' | |||
ORDER BY job_name, updated_unix DESC) a | |||
where status in ('STOPPED','SUCCEEDED','FAILED') and (((end_time is null or end_time=0) and updated_unix<? and updated_unix != 0 ) or (end_time<? and end_time != 0)) and cleared=false` | |||
return cloudbrains, x.Unscoped().SQL(sql,missEndTimeBefore, endTimeBefore).Limit(limit).Find(&cloudbrains) | |||
return cloudbrains, x.Unscoped().SQL(sql, missEndTimeBefore, endTimeBefore).Limit(limit).Find(&cloudbrains) | |||
} | |||
func UpdateCloudBrainRecordsCleared(ids []int64) error { | |||
pageSize := 150 | |||
n := len(ids) / pageSize | |||
@@ -1024,6 +1024,8 @@ func RegisterRoutes(m *macaron.Macaron) { | |||
m.Get("/query_model_byName", repo.QueryModelByName) | |||
m.Get("/query_model_for_predict", repo.QueryModelListForPredict) | |||
m.Get("/query_modelfile_for_predict", repo.QueryModelFileForPredict) | |||
m.Get("/query_train_job", repo.QueryTrainJobList) | |||
m.Get("/query_train_job_version", repo.QueryTrainJobVersionList) | |||
m.Get("/query_train_model", repo.QueryTrainModelList) | |||
m.Post("/create_model_convert", repo.CreateModelConvert) | |||
m.Post("/convert_stop", repo.StopModelConvert) | |||
@@ -4,8 +4,10 @@ import ( | |||
"net/http" | |||
"code.gitea.io/gitea/modules/context" | |||
"code.gitea.io/gitea/modules/convert" | |||
"code.gitea.io/gitea/modules/log" | |||
"code.gitea.io/gitea/modules/storage" | |||
api "code.gitea.io/gitea/modules/structs" | |||
routerRepo "code.gitea.io/gitea/routers/repo" | |||
) | |||
@@ -54,6 +56,21 @@ func QueryModelListForPredict(ctx *context.APIContext) { | |||
routerRepo.QueryModelListForPredict(ctx.Context) | |||
} | |||
func QueryTrainJobList(ctx *context.APIContext) { | |||
result, err := routerRepo.QueryTrainJobListApi(ctx.Context) | |||
if err != nil { | |||
log.Info("query error." + err.Error()) | |||
ctx.JSON(http.StatusOK, nil) | |||
} else { | |||
re := make([]*api.Cloudbrain, 0) | |||
for _, task := range result { | |||
conRe := convert.ToCloudBrain(&task.Cloudbrain) | |||
re = append(re, conRe) | |||
} | |||
ctx.JSON(http.StatusOK, re) | |||
} | |||
} | |||
func QueryTrainModelList(ctx *context.APIContext) { | |||
result, err := routerRepo.QueryTrainModelFileById(ctx.Context) | |||
if err != nil { | |||
@@ -63,6 +80,21 @@ func QueryTrainModelList(ctx *context.APIContext) { | |||
ctx.JSON(http.StatusOK, re) | |||
} | |||
func QueryTrainJobVersionList(ctx *context.APIContext) { | |||
result, err := routerRepo.QueryTrainJobVersionListApi(ctx.Context) | |||
if err != nil { | |||
log.Info("query error." + err.Error()) | |||
ctx.JSON(http.StatusOK, nil) | |||
} else { | |||
re := make([]*api.Cloudbrain, 0) | |||
for _, task := range result { | |||
conRe := convert.ToCloudBrain(task) | |||
re = append(re, conRe) | |||
} | |||
ctx.JSON(http.StatusOK, re) | |||
} | |||
} | |||
func convertFileFormat(result []storage.FileInfo) []FileInfo { | |||
re := make([]FileInfo, 0) | |||
if result != nil { | |||
@@ -2,7 +2,6 @@ package repo | |||
import ( | |||
"archive/zip" | |||
"code.gitea.io/gitea/services/repository" | |||
"encoding/json" | |||
"errors" | |||
"fmt" | |||
@@ -12,6 +11,8 @@ import ( | |||
"regexp" | |||
"strings" | |||
"code.gitea.io/gitea/services/repository" | |||
"code.gitea.io/gitea/models" | |||
"code.gitea.io/gitea/modules/context" | |||
"code.gitea.io/gitea/modules/log" | |||
@@ -710,36 +711,42 @@ func downloadFromCloudBrainTwo(path string, task *models.AiModelManage, ctx *con | |||
} | |||
func QueryTrainJobVersionList(ctx *context.Context) { | |||
VersionListTasks, err := QueryTrainJobVersionListApi(ctx) | |||
if err != nil { | |||
ctx.JSON(200, nil) | |||
} else { | |||
ctx.JSON(200, VersionListTasks) | |||
} | |||
} | |||
func QueryTrainJobVersionListApi(ctx *context.Context) ([]*models.Cloudbrain, error) { | |||
log.Info("query train job version list. start.") | |||
JobID := ctx.Query("jobId") | |||
if JobID == "" { | |||
JobID = ctx.Query("JobId") | |||
} | |||
VersionListTasks, count, err := models.QueryModelTrainJobVersionList(JobID) | |||
log.Info("query return count=" + fmt.Sprint(count)) | |||
return VersionListTasks, err | |||
} | |||
func QueryTrainJobList(ctx *context.Context) { | |||
VersionListTasks, err := QueryTrainJobListApi(ctx) | |||
if err != nil { | |||
ctx.ServerError("QueryTrainJobList:", err) | |||
ctx.JSON(200, nil) | |||
} else { | |||
ctx.JSON(200, VersionListTasks) | |||
} | |||
} | |||
func QueryTrainJobList(ctx *context.Context) { | |||
log.Info("query train job list. start.") | |||
func QueryTrainJobListApi(ctx *context.Context) ([]*models.CloudbrainInfo, error) { | |||
repoId := ctx.QueryInt64("repoId") | |||
VersionListTasks, count, err := models.QueryModelTrainJobList(repoId) | |||
log.Info("query return count=" + fmt.Sprint(count)) | |||
if err != nil { | |||
ctx.ServerError("QueryTrainJobList:", err) | |||
} else { | |||
ctx.JSON(200, VersionListTasks) | |||
} | |||
return VersionListTasks, err | |||
} | |||
func QueryTrainModelFileById(ctx *context.Context) ([]storage.FileInfo, error) { | |||