MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / UpdateMidjourneyTaskBulk

Function UpdateMidjourneyTaskBulk

controller/midjourney.go:20–172  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18)
19
20func UpdateMidjourneyTaskBulk() {
21 //imageModel := "midjourney"
22 ctx := context.TODO()
23 for {
24 time.Sleep(time.Duration(15) * time.Second)
25
26 tasks := model.GetAllUnFinishTasks()
27 if len(tasks) == 0 {
28 continue
29 }
30
31 common.LogInfo(ctx, fmt.Sprintf("检测到未完成的任务数有: %v", len(tasks)))
32 taskChannelM := make(map[int][]string)
33 taskM := make(map[string]*model.Midjourney)
34 nullTaskIds := make([]int, 0)
35 for _, task := range tasks {
36 if task.MjId == "" {
37 // 统计失败的未完成任务
38 nullTaskIds = append(nullTaskIds, task.Id)
39 continue
40 }
41 taskM[task.MjId] = task
42 taskChannelM[task.ChannelId] = append(taskChannelM[task.ChannelId], task.MjId)
43 }
44 if len(nullTaskIds) > 0 {
45 err := model.MjBulkUpdateByTaskIds(nullTaskIds, map[string]any{
46 "status": "FAILURE",
47 "progress": "100%",
48 })
49 if err != nil {
50 common.LogError(ctx, fmt.Sprintf("Fix null mj_id task error: %v", err))
51 } else {
52 common.LogInfo(ctx, fmt.Sprintf("Fix null mj_id task success: %v", nullTaskIds))
53 }
54 }
55 if len(taskChannelM) == 0 {
56 continue
57 }
58
59 for channelId, taskIds := range taskChannelM {
60 common.LogInfo(ctx, fmt.Sprintf("渠道 #%d 未完成的任务有: %d", channelId, len(taskIds)))
61 if len(taskIds) == 0 {
62 continue
63 }
64 midjourneyChannel, err := model.CacheGetChannel(channelId)
65 if err != nil {
66 common.LogError(ctx, fmt.Sprintf("CacheGetChannel: %v", err))
67 err := model.MjBulkUpdate(taskIds, map[string]any{
68 "fail_reason": fmt.Sprintf("获取渠道信息失败,请联系管理员,渠道ID:%d", channelId),
69 "status": "FAILURE",
70 "progress": "100%",
71 })
72 if err != nil {
73 common.LogInfo(ctx, fmt.Sprintf("UpdateMidjourneyTask error: %v", err))
74 }
75 continue
76 }
77 requestUrl := fmt.Sprintf("%s/mj/task/list-by-condition", *midjourneyChannel.BaseURL)

Callers 1

mainFunction · 0.92

Calls 13

GetAllUnFinishTasksFunction · 0.92
LogInfoFunction · 0.92
MjBulkUpdateByTaskIdsFunction · 0.92
LogErrorFunction · 0.92
CacheGetChannelFunction · 0.92
MjBulkUpdateFunction · 0.92
GetHttpClientFunction · 0.92
IncreaseUserQuotaFunction · 0.92
LogQuotaFunction · 0.92
RecordLogFunction · 0.92
checkMjTaskNeedUpdateFunction · 0.85
ErrorMethod · 0.80

Tested by

no test coverage detected