Files
web_huakui_server/app/skd/ipstat/sync.go
T
rootandClaude Opus 4.7 85c0071fd8 feat: 从黄果 NET hgdjnet-server 9bfbafe 导入 HKDJ 官网后端
来源:hgdjnet-server 9bfbafe10d417deea959bd53117bc88a10e60a83
项目身份 HKDJ / JHA-216,独立官网仓库,Jenkins 守卫键 hkdjnet
测试目录 /server/hkdj_net,App/Web API 30331/30332

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-10-16 11:20:04 +08:00

50 lines
1.1 KiB
Go

package ipstat
import (
"context"
"hkdj-web-server/pub/common/enum/redisconst"
"hkdj-web-server/pub/common/log"
"hkdj-web-server/pub/common/utils"
"hkdj-web-server/pub/models/ipdailystatmod"
"hkdj-web-server/pub/pubdef"
"hkdj-web-server/pub/redis"
"time"
)
const syncInterval = 5 * time.Minute
func StartSync() {
go func() {
syncOnce()
ticker := time.NewTicker(syncInterval)
defer ticker.Stop()
for range ticker.C {
syncOnce()
}
}()
}
func syncOnce() {
ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
defer cancel()
now := time.Now().In(utils.LocBJ)
appId := int64(pubdef.AppId)
for _, offset := range []int{0, -1} {
date := now.AddDate(0, 0, offset).Format("20060102")
key := redisconst.IpStatKey(appId, date)
count, err := redis.SCard(key)
if err != nil {
log.Warn("ipstat sync: SCard failed", log.Any("date", date), log.E(err))
continue
}
if err := ipdailystatmod.UpsertCount(ctx, appId, date, count); err != nil {
log.Warn("ipstat sync: UpsertCount failed",
log.Any("appId", appId), log.Any("date", date), log.E(err))
}
}
}