Skip to content

Commit

Permalink
fix: fix video process
Browse files Browse the repository at this point in the history
  • Loading branch information
Attack825 committed Aug 21, 2023
1 parent 098cd3c commit 1cb2714
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/models/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

// Video 视频表
type Video struct {
ID uint32 `gorm:"not null;primary_key;auto_increment""`
ID uint32 `gorm:"not null;primary_key;auto_increment"`
UserId uint32 `json:"user_id" gorm:"not null;"`
Title string `json:"title" gorm:"not null;"`
FileName string `json:"play_name" gorm:"not null;"`
Expand Down
4 changes: 2 additions & 2 deletions src/services/publish/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (a PublishServiceImpl) CreateVideo(ctx context.Context, request *publish.Cr
CoverName: coverName,
}

bytes, err := json.Marshal(raw)
marshal, err := json.Marshal(raw)
if err != nil {
resp = &publish.CreateVideoResponse{
StatusCode: strings.VideoServiceInnerErrorCode,
Expand All @@ -172,7 +172,7 @@ func (a PublishServiceImpl) CreateVideo(ctx context.Context, request *publish.Cr
amqp.Publishing{
DeliveryMode: amqp.Persistent,
ContentType: "text/plain",
Body: bytes,
Body: marshal,
Headers: headers,
})

Expand Down
23 changes: 19 additions & 4 deletions src/services/videoprocessor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"encoding/json"
"github.com/sirupsen/logrus"
"github.com/streadway/amqp"
"gorm.io/gorm/clause"
"os/exec"
"sync"
)
Expand Down Expand Up @@ -159,16 +160,30 @@ func Consume(channel *amqp.Channel) {
}

// 保存到数据库
err = database.Client.WithContext(ctx).Create(&raw).Error
if err != nil {
video := &models.Video{
ID: raw.VideoId,
UserId: raw.ActorId,
Title: raw.Title,
FileName: raw.FileName,
CoverName: raw.CoverName,
}
result := database.Client.Clauses(clause.OnConflict{
Columns: []clause.Column{{Name: "id"}},
DoUpdates: clause.AssignmentColumns([]string{"user_id", "title", "file_name", "cover_name"}),
}).Create(&video)
if result.Error != nil {
logger.WithFields(logrus.Fields{
"file_name": raw.FileName,
"cover_name": raw.CoverName,
"err": err,
}).Debug("failed to create db entry")
}).Errorf("Error when updating file information to database")
logging.SetSpanError(span, result.Error)
errorHandler(d, true, logger, &span)
span.End()
continue
}
logger.WithFields(logrus.Fields{
"entry": raw,
"entry": video,
}).Debug("saved db entry")

span.End()
Expand Down

0 comments on commit 1cb2714

Please sign in to comment.