(ctx context.Context, platform constant.TaskPlatform, channelId int, taskIds []string, taskM map[string]*model.Task)
| 28 | } |
| 29 | |
| 30 | func 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 | |
| 65 | func updateVideoSingleTask(ctx context.Context, adaptor channel.TaskAdaptor, channel *model.Channel, taskId string, taskM map[string]*model.Task) error { |
| 66 | baseURL := constant.ChannelBaseURLs[channel.Type] |
no test coverage detected