This commit is contained in:
2023-05-11 07:50:56 +08:00
parent 69973202e0
commit 2ab29d1e02
6 changed files with 110 additions and 0 deletions

View File

@@ -3,6 +3,9 @@ package models
import (
"log"
"main/configs"
"net/http"
"strconv"
"time"
)
type Task struct {
@@ -16,6 +19,49 @@ type Task struct {
UserID int `json:"user_id"`
}
// 推理任務
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
}
}
}
func (task *Task) Create() error {
db, err := configs.GetDB()
if err != nil {