fix: 配置查询日志改为每10秒打印一次
This commit is contained in:
parent
a72f5d884f
commit
6c1e016672
@ -4,6 +4,8 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"kfz-goods-pricing/internal/database"
|
"kfz-goods-pricing/internal/database"
|
||||||
)
|
)
|
||||||
@ -18,6 +20,11 @@ type KfzConfig struct {
|
|||||||
QueryIndex int
|
QueryIndex int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
lastConfigLog time.Time
|
||||||
|
configLogMu sync.Mutex
|
||||||
|
)
|
||||||
|
|
||||||
// GetKfzConfig 获取 kfz_config 配置(ID=1)
|
// GetKfzConfig 获取 kfz_config 配置(ID=1)
|
||||||
// 无数据时返回 nil, nil
|
// 无数据时返回 nil, nil
|
||||||
func GetKfzConfig() (*KfzConfig, error) {
|
func GetKfzConfig() (*KfzConfig, error) {
|
||||||
@ -34,8 +41,15 @@ func GetKfzConfig() (*KfzConfig, error) {
|
|||||||
log.Printf("[Repo/Config] 查询kfz_config失败: err=%v", err)
|
log.Printf("[Repo/Config] 查询kfz_config失败: err=%v", err)
|
||||||
return nil, fmt.Errorf("查询kfz_config失败: %w", err)
|
return nil, fmt.Errorf("查询kfz_config失败: %w", err)
|
||||||
}
|
}
|
||||||
log.Printf("[Repo/Config] 查询成功: new_price=%.2f, placeholder_down_price=%.2f, min_shipping_fee=%.2f, min_price=%.2f, query_index=%d",
|
configLogMu.Lock()
|
||||||
cfg.NewPrice, cfg.PlaceholderDownPrice, cfg.MinShippingFee, cfg.MinPrice, cfg.QueryIndex)
|
if time.Since(lastConfigLog) > 10*time.Second {
|
||||||
|
lastConfigLog = time.Now()
|
||||||
|
configLogMu.Unlock()
|
||||||
|
log.Printf("[Repo/Config] 查询成功: new_price=%.2f, placeholder_down_price=%.2f, min_shipping_fee=%.2f, min_price=%.2f, query_index=%d",
|
||||||
|
cfg.NewPrice, cfg.PlaceholderDownPrice, cfg.MinShippingFee, cfg.MinPrice, cfg.QueryIndex)
|
||||||
|
} else {
|
||||||
|
configLogMu.Unlock()
|
||||||
|
}
|
||||||
return &cfg, nil
|
return &cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user