fix:算法请求调整

This commit is contained in:
momo
2023-10-10 14:58:36 +08:00
parent 019a717706
commit 6e8d47ae91
6 changed files with 59 additions and 30 deletions

View File

@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"fusenapi/constants"
"fusenapi/model/gmodel"
"fusenapi/utils/curl"
@@ -18,19 +19,23 @@ import (
"gorm.io/gorm"
)
func NewImageHandle(gormDB *gorm.DB, bLMServiceUrl *string, awsSession *session.Session) ImageHandle {
var globalBLMServiceIndex int
func NewImageHandle(gormDB *gorm.DB, bLMServiceUrl *string, bLMServicePorts []string, awsSession *session.Session) ImageHandle {
return &defaultImageHandle{
MysqlConn: gormDB,
BLMServiceUrl: bLMServiceUrl,
AwsSession: awsSession,
MysqlConn: gormDB,
BLMServiceUrl: bLMServiceUrl,
BLMServicePorts: bLMServicePorts,
AwsSession: awsSession,
}
}
type (
defaultImageHandle struct {
MysqlConn *gorm.DB
BLMServiceUrl *string
AwsSession *session.Session
MysqlConn *gorm.DB
BLMServiceUrl *string
BLMServicePorts []string
AwsSession *session.Session
}
ImageHandle = interface {
@@ -168,6 +173,14 @@ type (
)
func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq) (*LogoInfoSetRes, error) {
fmt.Println("算法请求轮训下标:", globalBLMServiceIndex)
var bLMServicePort = l.BLMServicePorts[globalBLMServiceIndex]
if len(l.BLMServicePorts) == globalBLMServiceIndex {
globalBLMServiceIndex = 0
} else {
globalBLMServiceIndex = globalBLMServiceIndex + 1
}
var resultBLM constants.BLMServiceUrlResult
postMap := make(map[string]string, 2)
postMap["logo_url"] = in.LogoUrl
@@ -175,7 +188,7 @@ func (l *defaultImageHandle) LogoInfoSet(ctx context.Context, in *LogoInfoSetReq
logc.Infof(ctx, "算法请求--LOGO基础信息--开始时间:%v", time.Now().UTC())
err := curl.NewClient(ctx, &curl.Config{
BaseUrl: *l.BLMServiceUrl,
BaseUrl: *l.BLMServiceUrl + ":" + bLMServicePort,
Url: constants.BLMServiceUrlLogoFeatureExtraction,
}).PostJson(postMap, &resultBLM)
logc.Infof(ctx, "算法请求--LOGO基础信息--结束时间:%v", time.Now().UTC())
@@ -226,6 +239,14 @@ type TemplateTagColor struct {
}
func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq) (*LogoCombineRes, error) {
fmt.Println("算法请求轮训下标:", globalBLMServiceIndex)
var bLMServicePort = l.BLMServicePorts[globalBLMServiceIndex]
if len(l.BLMServicePorts) == globalBLMServiceIndex {
globalBLMServiceIndex = 0
} else {
globalBLMServiceIndex = globalBLMServiceIndex + 1
}
logoResourceId := s3url_to_s3id.GetS3ResourceIdFormUrl(in.LogoUrl)
if logoResourceId == "" {
return nil, errors.New("invalid logo url")
@@ -319,7 +340,7 @@ func (l *defaultImageHandle) LogoCombine(ctx context.Context, in *LogoCombineReq
var resultBLM constants.BLMServiceUrlResult
err = curl.NewClient(ctx, &curl.Config{
BaseUrl: *l.BLMServiceUrl,
BaseUrl: *l.BLMServiceUrl + ":" + bLMServicePort,
Url: constants.BLMServiceUrlLogoCombine,
RequireTimeout: time.Second * 15,
}).PostJson(postMap, &resultBLM)
@@ -409,6 +430,14 @@ type (
/* 图片裁剪 */
func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardReq) (*LogoStandardRes, error) {
fmt.Println("算法请求轮训下标:", globalBLMServiceIndex)
var bLMServicePort = l.BLMServicePorts[globalBLMServiceIndex]
if len(l.BLMServicePorts) == globalBLMServiceIndex {
globalBLMServiceIndex = 0
} else {
globalBLMServiceIndex = globalBLMServiceIndex + 1
}
var ismaxProportion bool
var imgColor []string
var logoStandardMetaData LogoStandardMetaData
@@ -453,7 +482,7 @@ func (l *defaultImageHandle) LogoStandard(ctx context.Context, in *LogoStandardR
logc.Infof(ctx, "算法请求--去背景--开始时间:%v", time.Now().UTC())
err = curl.NewClient(ctx, &curl.Config{
BaseUrl: *l.BLMServiceUrl,
BaseUrl: *l.BLMServiceUrl + ":" + bLMServicePort,
Url: constants.BLMServiceUrlLogoRemovebg,
}).PostJson(postMap, &resultBLM)
logc.Infof(ctx, "算法请求--去背景--结束时间:%v", time.Now().UTC())