diff --git a/api/consts/consts.go b/api/consts/consts.go index 28c9fceb..7d8702f1 100644 --- a/api/consts/consts.go +++ b/api/consts/consts.go @@ -31,6 +31,8 @@ const ( TagNumKey = "tag_num" PlatformNumKey = "platform_num" SupportWxIdNumKey = "support_wx_id_num" + ImageIdForUploadFail = "image_id_for_upload_fail" + VideoIdForUploadFail = "video_id_for_upload_fail" ) // del_flag @@ -58,7 +60,7 @@ const ( RedisStreamerPrefix = "streamer:" //streamer服务前缀 ) -//const PackageRootPath = "/Users/PC/Desktop/wishpal-ironfan" +//const PackageRootPath = "C:/Users/PC/Desktop/wishpal_ironfan_service/service" const PackageRootPath = "/app/wishpal-ironfan" diff --git a/app/mix/controller/config_op.go b/app/mix/controller/config_op.go index 79702988..212caf2d 100644 --- a/app/mix/controller/config_op.go +++ b/app/mix/controller/config_op.go @@ -59,3 +59,14 @@ func OpIsThereANewVersionAvailable(ctx *gin.Context) { ReplyOk(ctx, data) } + +func OpGetUploadMediaFailConfigList(ctx *gin.Context) { + config, ec := service.DefaultConfigService.OpGetUploadMediaFailConfigList(ctx) + if ec != errcode.ErrCodeOk { + logger.Error("OpGetUploadMediaFailConfigList fail, ec: %v", ec) + ReplyErrCodeMsg(ctx, ec) + return + } + + ReplyOk(ctx, config) +} diff --git a/app/mix/controller/init.go b/app/mix/controller/init.go index caca2ed9..983c2ddb 100644 --- a/app/mix/controller/init.go +++ b/app/mix/controller/init.go @@ -160,6 +160,10 @@ func Init(r *gin.Engine) { apiVersion := r.Group("/api/version", PrepareToC()) apiVersion.POST("is_there_a_new_version_available", middleware.JSONParamValidator(base.BaseRequest{}), OpIsThereANewVersionAvailable) + // 上传媒体失败配置 + apiUploadMediaFailConfig := r.Group("/api/upload_media_fail_config", PrepareToC()) + apiUploadMediaFailConfig.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), OpGetUploadMediaFailConfigList) + // =============================== 以下是服务,只允许内网调用 =============================== // op相关,直接调用服务,不调用gateway @@ -348,6 +352,10 @@ func Init(r *gin.Engine) { opSupportWxIdGroup := r.Group("/op/support_wx_id", PrepareOp()) opSupportWxIdGroup.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), middleware.JwtAuthenticator(), OpGetSupportWxIdList) + // 上传媒体失败配置 + opUploadMediaFailConfig := r.Group("/op/upload_media_fail_config", PrepareToC()) + opUploadMediaFailConfig.POST("list", middleware.JSONParamValidator(base.BaseRequest{}), OpGetUploadMediaFailConfigList) + // 账号相关 //accountGroup := r.Group("/account") diff --git a/app/mix/service/configservice.go b/app/mix/service/configservice.go index 7c6c0ee5..8b20ca92 100644 --- a/app/mix/service/configservice.go +++ b/app/mix/service/configservice.go @@ -146,3 +146,26 @@ func (s *ConfigService) OpIsThereANewVersionAvailable(ctx *gin.Context, baseRequ } return } + +func (s *ConfigService) OpGetUploadMediaFailConfigList(ctx *gin.Context) (uploadMediaFailConfigMap map[string]int64, ec errcode.ErrCode) { + ec = errcode.ErrCodeOk + + uploadMediaFailConfigMap = make(map[string]int64) + + imageIdForUploadFail, err := apollo.GetIntValue(consts.ImageIdForUploadFail, apollo.ApolloOpts().SetNamespace("application")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + return nil, errcode.ErrCodeApolloReadFail + } + + videoIdForUploadFail, err := apollo.GetIntValue(consts.VideoIdForUploadFail, apollo.ApolloOpts().SetNamespace("application")) + if err != nil { + logger.Error("Apollo read failed : %v", err) + return nil, errcode.ErrCodeApolloReadFail + } + + uploadMediaFailConfigMap["image_id_for_upload_fail"] = int64(imageIdForUploadFail) + uploadMediaFailConfigMap["video_id_for_upload_fail"] = int64(videoIdForUploadFail) + + return +} diff --git a/library/contentaudit/imageaudit/imageaudit.go b/library/contentaudit/imageaudit/imageaudit.go index 18adea9a..f6f1076d 100644 --- a/library/contentaudit/imageaudit/imageaudit.go +++ b/library/contentaudit/imageaudit/imageaudit.go @@ -34,7 +34,7 @@ func executeImageAuditTasks(tasks []*ImageAuditTaskControlBlock, batchId string) req, taskMap, actionMap, err := createScanImageAdvanceRequest(tasks, batchId) if err != nil { logger.Info("Create Scan ImageRequest fail: %v", err) - handleBatchError(batchId, err) + handleBatchError(tasks, batchId, err) return } @@ -46,7 +46,7 @@ func executeImageAuditTasks(tasks []*ImageAuditTaskControlBlock, batchId string) //_result, err := defaultImageAuditClient.ScanImageWithOptions(req, runtime) if err != nil { logger.Error("ScanImageAdvance fail : %v", err) - handleBatchError(batchId, err) + handleBatchError(tasks, batchId, err) return } @@ -357,7 +357,7 @@ func updateExpiredTasks(expiredTaskIds []string) (err error) { return } -func handleBatchError(batchId string, _err error) (err error) { +func handleBatchError(tasks []*ImageAuditTaskControlBlock, batchId string, _err error) (err error) { logger.Info("All tasks of this batchId: %v has failed, rolling back...", batchId) ctx := &gin.Context{} if err = _DefaultImageAudit.OpUpdateByBatchId(ctx, batchId, &dbstruct.ImageAudit{ @@ -375,60 +375,21 @@ func handleBatchError(batchId string, _err error) (err error) { logger.Error("_DefaultImageAuditTask OpUpdateByBatchId fail: %v\n", err) return } + + // 回退 + for _, task := range tasks { + if err = task.RollbackFunc(); err != nil { + if err = _DefaultImageAuditTask.OpUpdate(ctx, &imageaudittaskproto.OpUpdateReq{ + ImageAuditTask: &dbstruct.ImageAuditTask{ + Id: task.ImageAuditTask.Id, + Status: goproto.Int64(consts.ImageAudit_Failed), + Remarks: goproto.String("任务审核失败,回退失败,请联系管理员排查"), + }, + }); err != nil { + logger.Error("_DefaultImageAudit OpUpdate fail: %v\n", err) + } + } + } + return } - -// func createScanImageRequest(tasks []*ImageAuditTaskControlBlock, batchId string) (request *imageaudit.ScanImageRequest, -// taskMap map[int]*ImageAuditTaskControlBlock, actionMap map[string]*ImageAuditAction, err error) { - -// ctx := &gin.Context{} -// // todo:taskMap其实可以删掉 -// taskMap = make(map[int]*ImageAuditTaskControlBlock) // 图像审核索引号-task的map -// actionMap = make(map[string]*ImageAuditAction) // 动作Id号-action的map - -// // 1.获取所有图像信息 -// offset := 0 -// images := make([]mediafiller.MediaFillable, 0) -// for _, task := range tasks { -// // 写map记录 -// if actionMap[task.ActionId] == nil { // 写入actionMap -// actionMap[task.ActionId] = NewImageAuditAction() -// } -// actionMap[task.ActionId].Record(task) - -// //获取图像 -// for _, image := range task.Images { -// images = append(images, image) -// taskMap[offset] = task -// offset++ -// } -// } -// mediafiller.FillList(ctx, images) - -// // 2.打包图像url及图像审核id,转成ScanImageRequest -// reqTasks := make([]*imageaudit.ScanImageRequestTask, 0) -// for _, task := range tasks { -// if util.DerefInt64(task.ImageAuditTask.IsFragmented) == 1 { -// imageauditIds := util.DerefStringSlice(task.ImageAuditTask.ImageAuditFragmentIds) -// for i := range task.Images { -// reqTasks = append(reqTasks, &imageaudit.ScanImageRequestTask{ -// DataId: goproto.String(imageauditIds[i]), -// ImageURL: goproto.String(task.Images[i].Images[0].Urls[0]), -// }) -// } -// } else { -// reqTasks = append(reqTasks, &imageaudit.ScanImageRequestTask{ -// DataId: task.ImageAuditTask.ImageAuditId, -// ImageURL: goproto.String(task.Images[0].Images[0].Urls[0]), -// }) -// } - -// } - -// request = &imageaudit.ScanImageRequest{ -// Scene: scenes, -// Task: reqTasks, -// } -// logger.Info("本次打包:%v", reqTasks) -// return -// } diff --git a/library/contentaudit/textaudit/textaudit.go b/library/contentaudit/textaudit/textaudit.go index 2cb01660..ee96f9b1 100644 --- a/library/contentaudit/textaudit/textaudit.go +++ b/library/contentaudit/textaudit/textaudit.go @@ -29,7 +29,7 @@ func executeTextAuditTasks(tasks []*TextAuditTaskControlBlock, batchId string) ( req, actionMap, err := createScanTextRequest(tasks, batchId) if err != nil { logger.Info("Create Scan TextRequest fail: %v", err) - handleBatchError(batchId, err) + handleBatchError(tasks, batchId, err) return } @@ -40,7 +40,7 @@ func executeTextAuditTasks(tasks []*TextAuditTaskControlBlock, batchId string) ( _result, err := defaultTextAuditClient.ScanTextWithOptions(req, runtime) if err != nil { logger.Error("ScanTextWithOptions fail : %v", err) - handleBatchError(batchId, err) + handleBatchError(tasks, batchId, err) return } @@ -296,7 +296,7 @@ func updateExpiredTasks(expiredTaskIds []string) (err error) { return } -func handleBatchError(batchId string, _err error) (err error) { +func handleBatchError(tasks []*TextAuditTaskControlBlock, batchId string, _err error) (err error) { logger.Info("All tasks of this batchId: %v has failed, rolling back...", batchId) ctx := &gin.Context{} if err = _DefaultTextAudit.OpUpdateByBatchId(ctx, batchId, &dbstruct.TextAudit{ @@ -314,5 +314,20 @@ func handleBatchError(batchId string, _err error) (err error) { logger.Error("_DefaultTextAuditTask OpUpdateByBatchId fail: %v\n", err) return } + + // 回退 + for _, task := range tasks { + if err = task.RollbackFunc(); err != nil { + if err = _DefaultTextAuditTask.OpUpdate(ctx, &textaudittaskproto.OpUpdateReq{ + TextAuditTask: &dbstruct.TextAuditTask{ + Id: task.TextAuditTask.Id, + Status: goproto.Int64(consts.ImageAudit_Failed), + Remarks: goproto.String("任务审核失败,回退失败,请联系管理员排查"), + }, + }); err != nil { + logger.Error("_DefaultTextAudit OpUpdate fail: %v\n", err) + } + } + } return }