You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
53 lines
1.3 KiB
53 lines
1.3 KiB
package msg
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
const GlOBLLOCK = "GLOBAL_LOCK"
|
|
|
|
type MessageLocker interface {
|
|
LockMessageTypeKey(ctx context.Context, clientMsgID, typeKey string) (err error)
|
|
UnLockMessageTypeKey(ctx context.Context, clientMsgID string, typeKey string) error
|
|
LockGlobalMessage(ctx context.Context, clientMsgID string) (err error)
|
|
UnLockGlobalMessage(ctx context.Context, clientMsgID string) (err error)
|
|
}
|
|
type LockerMessage struct{}
|
|
|
|
func NewLockerMessage() *LockerMessage {
|
|
return &LockerMessage{}
|
|
}
|
|
func (l *LockerMessage) LockMessageTypeKey(clientMsgID, typeKey string) (err error) {
|
|
for i := 0; i < 3; i++ {
|
|
err = db.DB.LockMessageTypeKey(clientMsgID, typeKey)
|
|
if err != nil {
|
|
time.Sleep(time.Millisecond * 100)
|
|
continue
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
return err
|
|
|
|
}
|
|
func (l *LockerMessage) LockGlobalMessage(clientMsgID string) (err error) {
|
|
for i := 0; i < 3; i++ {
|
|
err = db.DB.LockMessageTypeKey(clientMsgID, GlOBLLOCK)
|
|
if err != nil {
|
|
time.Sleep(time.Millisecond * 100)
|
|
continue
|
|
} else {
|
|
break
|
|
}
|
|
}
|
|
return err
|
|
|
|
}
|
|
func (l *LockerMessage) UnLockMessageTypeKey(clientMsgID string, typeKey string) error {
|
|
return db.DB.UnLockMessageTypeKey(clientMsgID, typeKey)
|
|
}
|
|
func (l *LockerMessage) UnLockGlobalMessage(clientMsgID string) error {
|
|
return db.DB.UnLockMessageTypeKey(clientMsgID, GlOBLLOCK)
|
|
}
|