@@ -0,0 +1,49 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user