优化数据库相关代码

This commit is contained in:
刘祥超
2022-04-08 14:15:45 +08:00
parent fe448e6556
commit c03d9f1880
10 changed files with 99 additions and 16 deletions

View File

@@ -77,18 +77,27 @@ func (this *ServerAccessLogCleaner) Loop() error {
return err
}
for _, node := range nodes {
dbConfig := node.DBConfig()
db, err := dbs.NewInstanceFromConfig(dbConfig)
if err != nil {
return err
}
err = this.cleanDB(db, endDay)
if err != nil {
_ = db.Close()
return err
}
err := func(node *models.DBNode) error {
var dbConfig = node.DBConfig()
nodeDB, err := dbs.NewInstanceFromConfig(dbConfig)
if err != nil {
return err
}
_ = db.Close()
defer func() {
_ = nodeDB.Close()
}()
err = this.cleanDB(nodeDB, endDay)
if err != nil {
return err
}
return nil
}(node)
if err != nil {
return err
}
}
return nil