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

Function updateVideoSingleTask

controller/task_video.go:53–138  ·  view source on GitHub ↗
(ctx context.Context, adaptor channel.TaskAdaptor, channel *model.Channel, taskId string, taskM map[string]*model.Task)

Source from the content-addressed store, hash-verified

51}
52
53func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, channel *model.Channel, taskId string, taskM map[string]*model.Task) error {
54 baseURL := constant.ChannelBaseURLs[channel.Type]
55 if channel.GetBaseURL() != "" {
56 baseURL = channel.GetBaseURL()
57 }
58
59 task := taskM[taskId]
60 if task == nil {
61 common.LogError(ctx, fmt.Sprintf("Task %s not found in taskM", taskId))
62 return fmt.Errorf("task %s not found", taskId)
63 }
64 resp, err := adaptor.FetchTask(baseURL, channel.Key, map[string]any{
65 "task_id": taskId,
66 "action": task.Action,
67 })
68 if err != nil {
69 return fmt.Errorf("fetchTask failed for task %s: %w", taskId, err)
70 }
71 //if resp.StatusCode != http.StatusOK {
72 //return fmt.Errorf("get Video Task status code: %d", resp.StatusCode)
73 //}
74 defer resp.Body.Close()
75 responseBody, err := io.ReadAll(resp.Body)
76 if err != nil {
77 return fmt.Errorf("readAll failed for task %s: %w", taskId, err)
78 }
79
80 taskResult, err := adaptor.ParseTaskResult(responseBody)
81 if err != nil {
82 return fmt.Errorf("parseTaskResult failed for task %s: %w", taskId, err)
83 }
84 //if taskResult.Code != 0 {
85 // return fmt.Errorf("video task fetch failed for task %s", taskId)
86 //}
87
88 now := time.Now().Unix()
89 if taskResult.Status == "" {
90 return fmt.Errorf("task %s status is empty", taskId)
91 }
92 task.Status = model.TaskStatus(taskResult.Status)
93 switch taskResult.Status {
94 case model.TaskStatusSubmitted:
95 task.Progress = "10%"
96 case model.TaskStatusQueued:
97 task.Progress = "20%"
98 case model.TaskStatusInProgress:
99 task.Progress = "30%"
100 if task.StartTime == 0 {
101 task.StartTime = now
102 }
103 case model.TaskStatusSuccess:
104 task.Progress = "100%"
105 if task.FinishTime == 0 {
106 task.FinishTime = now
107 }
108 task.FailReason = taskResult.Url
109 case model.TaskStatusFailure:
110 task.Status = model.TaskStatusFailure

Callers 1

updateVideoTaskAllFunction · 0.85

Calls 12

LogErrorFunction · 0.92
TaskStatusTypeAlias · 0.92
LogInfoFunction · 0.92
IncreaseUserQuotaFunction · 0.92
LogQuotaFunction · 0.92
RecordLogFunction · 0.92
SysErrorFunction · 0.92
GetBaseURLMethod · 0.80
ErrorMethod · 0.80
FetchTaskMethod · 0.65
ParseTaskResultMethod · 0.65
UpdateMethod · 0.45

Tested by

no test coverage detected