MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / UpdateTaskBulk

Function UpdateTaskBulk

controller/task.go:23–70  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

21)
22
23func UpdateTaskBulk() {
24 //revocer
25 //imageModel := "midjourney"
26 for {
27 time.Sleep(time.Duration(15) * time.Second)
28 common.SysLog("任务进度轮询开始")
29 ctx := context.TODO()
30 allTasks := model.GetAllUnFinishSyncTasks(500)
31 platformTask := make(map[constant.TaskPlatform][]*model.Task)
32 for _, t := range allTasks {
33 platformTask[t.Platform] = append(platformTask[t.Platform], t)
34 }
35 for platform, tasks := range platformTask {
36 if len(tasks) == 0 {
37 continue
38 }
39 taskChannelM := make(map[int][]string)
40 taskM := make(map[string]*model.Task)
41 nullTaskIds := make([]int64, 0)
42 for _, task := range tasks {
43 if task.TaskID == "" {
44 // 统计失败的未完成任务
45 nullTaskIds = append(nullTaskIds, task.ID)
46 continue
47 }
48 taskM[task.TaskID] = task
49 taskChannelM[task.ChannelId] = append(taskChannelM[task.ChannelId], task.TaskID)
50 }
51 if len(nullTaskIds) > 0 {
52 err := model.TaskBulkUpdateByID(nullTaskIds, map[string]any{
53 "status": "FAILURE",
54 "progress": "100%",
55 })
56 if err != nil {
57 common.LogError(ctx, fmt.Sprintf("Fix null task_id task error: %v", err))
58 } else {
59 common.LogInfo(ctx, fmt.Sprintf("Fix null task_id task success: %v", nullTaskIds))
60 }
61 }
62 if len(taskChannelM) == 0 {
63 continue
64 }
65
66 UpdateTaskByPlatform(platform, taskChannelM, taskM)
67 }
68 common.SysLog("任务进度轮询完成")
69 }
70}
71
72func UpdateTaskByPlatform(platform constant.TaskPlatform, taskChannelM map[int][]string, taskM map[string]*model.Task) {
73 switch platform {

Callers 1

mainFunction · 0.92

Calls 6

SysLogFunction · 0.92
GetAllUnFinishSyncTasksFunction · 0.92
TaskBulkUpdateByIDFunction · 0.92
LogErrorFunction · 0.92
LogInfoFunction · 0.92
UpdateTaskByPlatformFunction · 0.85

Tested by

no test coverage detected