fix: 暂时修复死锁问题。sleep

main
NorthLan 3 years ago
parent 9f4cc52b62
commit 310a2dcb5c

@ -78,7 +78,7 @@ func (m *customRankPvpModel) RankListByType(ctx context.Context, rankType, topN
} }
func (m *customRankPvpModel) UpdateRank(ctx context.Context, rankType int32, data []RankPvp) error { func (m *customRankPvpModel) UpdateRank(ctx context.Context, rankType int32, data []RankPvp) error {
db := m.conn.WithContext(ctx) //.Session(&gorm.Session{DryRun: true}) db := m.conn.WithContext(ctx)
return db.Transaction(func(tx *gorm.DB) error { return db.Transaction(func(tx *gorm.DB) error {
var err error var err error
// delete all by rank_type // delete all by rank_type

@ -11,6 +11,7 @@ import (
"live-service/app/user_center/model" "live-service/app/user_center/model"
"live-service/app/user_center/rpc/internal/svc" "live-service/app/user_center/rpc/internal/svc"
"live-service/app/user_center/rpc/pb" "live-service/app/user_center/rpc/pb"
"time"
) )
var Service *Job var Service *Job
@ -300,6 +301,8 @@ func (j *Job) persistence(rankType int32) {
}) })
} }
if len(dbModel) > 0 { if len(dbModel) > 0 {
// 简单避免死锁
time.Sleep(1 * time.Second)
if err = j.svcCtx.RankPvpModel.UpdateRank(j.ctx, rankType, dbModel); err != nil { if err = j.svcCtx.RankPvpModel.UpdateRank(j.ctx, rankType, dbModel); err != nil {
logx.Error("更新排行榜错误", err) logx.Error("更新排行榜错误", err)
return return

Loading…
Cancel
Save