64 lines
963 B
Go
64 lines
963 B
Go
package logic
|
|
|
|
import (
|
|
"sync/atomic"
|
|
"time"
|
|
|
|
"mbase/app/maindb"
|
|
"mbase/pkg/logger"
|
|
)
|
|
|
|
type LogicConfig struct {
|
|
Database *maindb.Database
|
|
}
|
|
|
|
type Logic struct {
|
|
log *logger.Logger
|
|
db *maindb.Database
|
|
dumpingSem atomic.Bool
|
|
restoringSem atomic.Bool
|
|
}
|
|
|
|
func NewLogic(conf *LogicConfig) (*Logic, error) {
|
|
var err error
|
|
lg := &Logic{
|
|
db: conf.Database,
|
|
}
|
|
lg.log = logger.NewLogger("logic")
|
|
return lg, err
|
|
}
|
|
|
|
func (lg *Logic) DumpingSemUp() {
|
|
lg.dumpingSem.Store(true)
|
|
}
|
|
|
|
func (lg *Logic) DumpingSemDown() {
|
|
lg.dumpingSem.Store(false)
|
|
}
|
|
|
|
func (lg *Logic) WaitDumping() {
|
|
for {
|
|
if !lg.dumpingSem.Load() {
|
|
return
|
|
}
|
|
time.Sleep(1 * time.Millisecond)
|
|
}
|
|
}
|
|
|
|
func (lg *Logic) RestoringSemUp() {
|
|
lg.restoringSem.Store(true)
|
|
}
|
|
|
|
func (lg *Logic) RestoringSemDown() {
|
|
lg.restoringSem.Store(false)
|
|
}
|
|
|
|
func (lg *Logic) WaitRestoring() {
|
|
for {
|
|
if !lg.restoringSem.Load() {
|
|
return
|
|
}
|
|
time.Sleep(1 * time.Millisecond)
|
|
}
|
|
}
|