Files
huangguo_server/skd/skdg/shortrecommend.go
T
rootandClaude Opus 5 8679200f41 Initial commit
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-15 13:57:10 +08:00

50 lines
1.3 KiB
Go

package skdg
const (
defaultShortRecommendCron = "CRON_TZ=Asia/Shanghai 0 5/10 * * * ?"
defaultShortRecommendKeyTTLHours = 72
defaultProdInitializationLimit = 50_000
)
// ShortRecommendConfig 控制定时队列生成。Enabled 未配置时默认启用。
type ShortRecommendConfig struct {
Enabled *bool `json:"enabled"`
Cron string `json:"cron"`
KeyTTLHours int `json:"keyTTLHours"`
MaxInitializationWrites *int64 `json:"maxInitializationWrites"`
}
func (c *GlobalConfig) ShortRecommendEnabled() bool {
return c == nil || c.ShortRecommend.Enabled == nil || *c.ShortRecommend.Enabled
}
func (c *GlobalConfig) ShortRecommendCron() string {
if c == nil || c.ShortRecommend.Cron == "" {
return defaultShortRecommendCron
}
return c.ShortRecommend.Cron
}
func (c *GlobalConfig) ShortRecommendKeyTTL() int {
if c == nil || c.ShortRecommend.KeyTTLHours <= 0 {
return defaultShortRecommendKeyTTLHours
}
return c.ShortRecommend.KeyTTLHours
}
func (c *GlobalConfig) ShortRecommendInitializationLimit() int64 {
if c == nil {
return 0
}
if c.ShortRecommend.MaxInitializationWrites != nil {
if *c.ShortRecommend.MaxInitializationWrites < 0 {
return 0
}
return *c.ShortRecommend.MaxInitializationWrites
}
if c.Base.Env == "prod" {
return defaultProdInitializationLimit
}
return 0
}