58 lines
1.2 KiB
Go
58 lines
1.2 KiB
Go
package models
|
|
|
|
import "time"
|
|
|
|
type Task struct {
|
|
ID int `json:"id" gorm:"primary_key"`
|
|
Name string `json:"name"`
|
|
Type string `json:"type"` // 任務類型(訓練|推理)
|
|
Status string `json:"status"` // (initial|ready|waiting|running|success|error)
|
|
Progress int `json:"progress"` // (0-100)
|
|
UserID int `json:"user_id"`
|
|
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
|
|
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
|
|
}
|
|
|
|
//// 推理任務
|
|
//func startInferenceTask(task *Task) {
|
|
//
|
|
// // 獲取一臺可用的 GPU 資源
|
|
// // ...
|
|
//
|
|
// // 執行推理任務
|
|
// // ...
|
|
//
|
|
// // 更新任務狀態
|
|
// task.Status = "running"
|
|
// task.Progress = 0
|
|
// task.Update()
|
|
//
|
|
// // 監聽任務狀態
|
|
// for {
|
|
// // 延遲 1 秒
|
|
// time.Sleep(1 * time.Second)
|
|
//
|
|
// // 查詢任務狀態
|
|
// resp, err := http.Get("http://localhost:5000/api/v1/tasks/" + strconv.Itoa(task.ID))
|
|
// if err != nil {
|
|
// log.Println(err)
|
|
// continue
|
|
// }
|
|
// defer resp.Body.Close()
|
|
//
|
|
// // 解析任務狀態
|
|
// // ...
|
|
//
|
|
// // 更新任務狀態
|
|
// task.Progress = 100
|
|
// task.Status = "success"
|
|
// task.Update()
|
|
//
|
|
// // 任務結束判定
|
|
// if task.Progress == 100 {
|
|
// break
|
|
// }
|
|
// }
|
|
//
|
|
//}
|