delete strategy which does not found nid

This commit is contained in:
710leo 2020-04-13 19:27:24 +08:00
parent 99ca7fb862
commit 4b7262f18d
2 changed files with 34 additions and 1 deletions

View File

@ -29,7 +29,7 @@ func SyncStra() error {
list, err := model.StrasAll()
if err != nil {
stats.Counter.Set("mcache.stra.sync.err", 1)
return fmt.Errorf("model.StrasAll fail: %v", err)
return fmt.Errorf("get stras fail: %v", err)
}
smap := make(map[int64]*model.Stra)
@ -42,3 +42,35 @@ func SyncStra() error {
mcache.StraCache.SetAll(smap)
return nil
}
func CleanStraLoop() {
duration := time.Second * time.Duration(300)
for {
time.Sleep(duration)
CleanStra()
}
}
//定期清理没有找到nid的策略
func CleanStra() {
list, err := model.StrasAll()
if err != nil {
logger.Errorf("get stras fail: %v", err)
return
}
for _, stra := range list {
node, err := model.NodeGet("id", stra.Nid)
if err != nil {
logger.Warning("get node failed, node id: %v, err: %v", stra.Nid, err)
continue
}
if node == nil {
logger.Infof("delete stra:%d", stra.Id)
if err := model.StraDel(stra.Id); err != nil {
logger.Warning("delete stra: %d, err: %v", stra.Id, err)
}
}
}
}

View File

@ -81,6 +81,7 @@ func main() {
go cron.SyncMaskconfLoop()
go cron.SyncStraLoop()
go cron.CleanStraLoop()
go cron.EventConsumer()
go cron.CallbackConsumer()
go cron.CleanEventLoop()