|
|
@@ -2,6 +2,8 @@ package cloudbrainTask |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"net/http" |
|
|
"net/http" |
|
|
|
|
|
"os" |
|
|
|
|
|
"strings" |
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models" |
|
|
"code.gitea.io/gitea/models" |
|
|
"code.gitea.io/gitea/modules/cloudbrain" |
|
|
"code.gitea.io/gitea/modules/cloudbrain" |
|
|
@@ -9,6 +11,7 @@ import ( |
|
|
"code.gitea.io/gitea/modules/log" |
|
|
"code.gitea.io/gitea/modules/log" |
|
|
"code.gitea.io/gitea/modules/notification" |
|
|
"code.gitea.io/gitea/modules/notification" |
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
"code.gitea.io/gitea/modules/setting" |
|
|
|
|
|
"code.gitea.io/gitea/modules/storage" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
var noteBookOKMap = make(map[int64]int, 20) |
|
|
var noteBookOKMap = make(map[int64]int, 20) |
|
|
@@ -46,6 +49,11 @@ func SyncCloudBrainOneStatus(task *models.Cloudbrain) (*models.Cloudbrain, error |
|
|
task.Status = result.JobStatus.State |
|
|
task.Status = result.JobStatus.State |
|
|
if oldStatus != task.Status { |
|
|
if oldStatus != task.Status { |
|
|
notification.NotifyChangeCloudbrainStatus(task, oldStatus) |
|
|
notification.NotifyChangeCloudbrainStatus(task, oldStatus) |
|
|
|
|
|
err := updateLogFile(task, result) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Error("updateLogFile failed:", err) |
|
|
|
|
|
return task, err |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
err = models.UpdateJob(task) |
|
|
err = models.UpdateJob(task) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
@@ -57,6 +65,43 @@ func SyncCloudBrainOneStatus(task *models.Cloudbrain) (*models.Cloudbrain, error |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func updateLogFile(task *models.Cloudbrain, result models.JobResultPayload) error { |
|
|
|
|
|
if task.Type == models.TypeCloudBrainOne { |
|
|
|
|
|
taskRoles := result.TaskRoles |
|
|
|
|
|
taskRes, _ := models.ConvertToTaskPod(taskRoles[cloudbrain.SubTaskName].(map[string]interface{})) |
|
|
|
|
|
existStr := taskRes.TaskStatuses[0].ExitDiagnostics |
|
|
|
|
|
logDir := "/model" |
|
|
|
|
|
files, err := storage.GetOneLevelAllObjectUnderDirMinio(setting.Attachment.Minio.Bucket, setting.CBCodePathPrefix+task.JobName+logDir, "") |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Error("query cloudbrain model failed: %v", err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
fileName := "" |
|
|
|
|
|
for _, file := range files { |
|
|
|
|
|
if strings.HasSuffix(file.FileName, "log.txt") { |
|
|
|
|
|
fileName = file.FileName |
|
|
|
|
|
break |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
if fileName != "" { |
|
|
|
|
|
prefix := "/" + setting.CBCodePathPrefix + task.JobName + "/model" |
|
|
|
|
|
configFile, err := os.OpenFile(setting.Attachment.Minio.RealPath+setting.Attachment.Minio.Bucket+prefix+"/"+fileName, os.O_WRONLY|os.O_APPEND, 0666) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Error("open file(%s) failed:%s", prefix+fileName, err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
defer configFile.Close() |
|
|
|
|
|
_, err = configFile.WriteString(existStr) |
|
|
|
|
|
if err != nil { |
|
|
|
|
|
log.Error("WriteString failed:%v", err) |
|
|
|
|
|
return err |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
return nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func isNoteBookReady(task *models.Cloudbrain) bool { |
|
|
func isNoteBookReady(task *models.Cloudbrain) bool { |
|
|
if task.JobType != string(models.JobTypeDebug) { |
|
|
if task.JobType != string(models.JobTypeDebug) { |
|
|
return true |
|
|
return true |
|
|
|