delete strategy which does not found nid
This commit is contained in:
parent
99ca7fb862
commit
4b7262f18d
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -81,6 +81,7 @@ func main() {
|
|||
|
||||
go cron.SyncMaskconfLoop()
|
||||
go cron.SyncStraLoop()
|
||||
go cron.CleanStraLoop()
|
||||
go cron.EventConsumer()
|
||||
go cron.CallbackConsumer()
|
||||
go cron.CleanEventLoop()
|
||||
|
|
Loading…
Reference in New Issue