作者 郑周

Merge branch 'dev-zhengzhou' into test

... ... @@ -2,6 +2,7 @@ package service
import (
"fmt"
"gitlab.fjmaimaimai.com/allied-creation/performance/pkg/infrastructure/xredis"
"strconv"
"strings"
"time"
... ... @@ -501,6 +502,15 @@ func (rs *EvaluationProjectService) List(in *command.QueryProjectCommand) (inter
}
func (rs *EvaluationProjectService) Activate(in *command.ActivateProjectCommand) (interface{}, error) {
lock := xredis.NewLockProjectId(int(in.Id))
err := lock.Lock()
if err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
}
defer func() {
lock.UnLock()
}()
transactionContext, err := factory.ValidateStartTransaction(in)
if err != nil {
return nil, err
... ...
package xredis
import (
"fmt"
"github.com/go-redsync/redsync/v4"
)
type LockProjectId struct {
m *redsync.Mutex
}
func NewLockProjectId(id int) *LockProjectId {
key := fmt.Sprintf("performance:project_id:%d", id)
return &LockProjectId{
m: rsync.NewMutex(key),
}
}
func (lk *LockProjectId) Lock() error {
return lk.m.Lock()
}
func (lk *LockProjectId) UnLock() (bool, error) {
return lk.m.Unlock()
}
... ...