Skip to content

Commit

Permalink
Merge pull request #237 from GuGoOrg/endymx
Browse files Browse the repository at this point in the history
Endymx
  • Loading branch information
liaosunny123 committed Sep 9, 2023
2 parents e059d92 + 4a67c6d commit 4c0a4ef
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ services:
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- discovery.type=single-node
- cluster.routing.allocation.disk.threshold_enabled=false
ulimits:
memlock:
soft: -1
Expand Down
2 changes: 2 additions & 0 deletions src/constant/config/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,5 @@ const Event = "GuGoTik-Recommend"
const MsgConsumer = "GuGoTik-MgsConsumer"

const BloomRedisChannel = "GuGoTik-Bloom"

const MaxVideoSize = 200 * 1024 * 1024
2 changes: 2 additions & 0 deletions src/constant/strings/err.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,6 @@ const (
FollowLimited = "关注频繁,请稍后再试!"
UserDoNotExistedCode = 10013
UserDoNotExisted = "查询用户不存在!"
OversizeVideoCode = 10014
OversizeVideo = "上传视频超过了200MB"
)
27 changes: 21 additions & 6 deletions src/services/msgconsumer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@ func saveMessage(channel *amqp.Channel) {
ctx, span := tracing.Tracer.Start(ctx, "MessageSendService")
logger := logging.LogService("MessageSend").WithContext(ctx)

// Check if it is a re-publish message
retry, ok := body.Headers["x-retry"].(int32)
if ok || retry >= 1 {
err := body.Ack(false)
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message...")
logging.SetSpanError(span, err)
}
span.End()
continue
}

if err := json.Unmarshal(body.Body, &message); err != nil {
logger.WithFields(logrus.Fields{
"from_id": message.FromUserId,
Expand Down Expand Up @@ -280,10 +294,10 @@ func saveMessage(channel *amqp.Channel) {
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message...3")
}).Errorf("Error when dealing with the message...")
logging.SetSpanError(span, err)

}
span.End()
}
}

Expand Down Expand Up @@ -369,15 +383,15 @@ func chatWithGPT(channel *amqp.Channel) {
}
logger.Infof("Successfully send the reply to user")

span.End()
err = body.Ack(false)

if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message...4")
}).Errorf("Error when dealing with the message...")
logging.SetSpanError(span, err)
}
span.End()
}
}

Expand Down Expand Up @@ -470,6 +484,7 @@ func saveAuditAction(channel *amqp.Channel) {
}).Errorf("Error when dealing with the action...")
logging.SetSpanError(span, err)
}
span.End()
}
}

Expand All @@ -496,7 +511,7 @@ func errorHandler(channel *amqp.Channel, d amqp.Delivery, requeue bool, logger *
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message event...1")
}).Errorf("Error when dealing with the message event...")
}
} else {
curRetry++
Expand All @@ -508,7 +523,7 @@ func errorHandler(channel *amqp.Channel, d amqp.Delivery, requeue bool, logger *
if err != nil {
logger.WithFields(logrus.Fields{
"err": err,
}).Errorf("Error when dealing with the message event...2")
}).Errorf("Error when dealing with the message event...")
}

logger.Debugf("Retrying %d times", curRetry)
Expand Down
2 changes: 1 addition & 1 deletion src/services/publish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func main() {
)
reg := prom.Client
reg.MustRegister(srvMetrics)
maxSize := 500 * 1024 * 1024
maxSize := config.MaxVideoSize

s := grpc.NewServer(
grpc.MaxRecvMsgSize(maxSize),
Expand Down
11 changes: 11 additions & 0 deletions src/web/publish/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,17 @@ func ActionPublishHandle(c *gin.Context) {
}
}(opened)

if file.Size > config.MaxVideoSize {
logger.WithFields(logrus.Fields{
"FileSize": file.Size,
}).Errorf("Maximum file size is 200MB")
c.JSON(http.StatusOK, models.ActionPublishRes{
StatusCode: strings.OversizeVideoCode,
StatusMsg: strings.OversizeVideo,
})
return
}

var data = make([]byte, file.Size)
readSize, err := opened.Read(data)
if err != nil {
Expand Down

0 comments on commit 4c0a4ef

Please sign in to comment.