MCPcopy
hub / github.com/QuantumNous/new-api / updateVideoTaskAll

Function updateVideoTaskAll

controller/task_video.go:30–63  ·  view source on GitHub ↗
(ctx context.Context, platform constant.TaskPlatform, channelId int, taskIds []string, taskM map[string]*model.Task)

Source from the content-addressed store, hash-verified

28}
29
30func updateVideoTaskAll(ctx context.Context, platform constant.TaskPlatform, channelId int, taskIds []string, taskM map[string]*model.Task) error {
31 logger.LogInfo(ctx, fmt.Sprintf("Channel #%d pending video tasks: %d", channelId, len(taskIds)))
32 if len(taskIds) == 0 {
33 return nil
34 }
35 cacheGetChannel, err := model.CacheGetChannel(channelId)
36 if err != nil {
37 errUpdate := model.TaskBulkUpdate(taskIds, map[string]any{
38 "fail_reason": fmt.Sprintf("Failed to get channel info, channel ID: %d", channelId),
39 "status": "FAILURE",
40 "progress": "100%",
41 })
42 if errUpdate != nil {
43 common.SysLog(fmt.Sprintf("UpdateVideoTask error: %v", errUpdate))
44 }
45 return fmt.Errorf("CacheGetChannel failed: %w", err)
46 }
47 adaptor := relay.GetTaskAdaptor(platform)
48 if adaptor == nil {
49 return fmt.Errorf("video adaptor not found")
50 }
51 info := &relaycommon.RelayInfo{}
52 info.ChannelMeta = &relaycommon.ChannelMeta{
53 ChannelBaseUrl: cacheGetChannel.GetBaseURL(),
54 }
55 info.ApiKey = cacheGetChannel.Key
56 adaptor.Init(info)
57 for _, taskId := range taskIds {
58 if err := updateVideoSingleTask(ctx, adaptor, cacheGetChannel, taskId, taskM); err != nil {
59 logger.LogError(ctx, fmt.Sprintf("Failed to update video task %s: %s", taskId, err.Error()))
60 }
61 }
62 return nil
63}
64
65func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, channel *model.Channel, taskId string, taskM map[string]*model.Task) error {
66 baseURL := constant.ChannelBaseURLs[channel.Type]

Callers 1

UpdateVideoTaskAllFunction · 0.85

Calls 9

LogInfoFunction · 0.92
CacheGetChannelFunction · 0.92
TaskBulkUpdateFunction · 0.92
GetTaskAdaptorFunction · 0.92
LogErrorFunction · 0.92
GetBaseURLMethod · 0.80
updateVideoSingleTaskFunction · 0.70
InitMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected