@@ -0,0 +1,43 @@
|
||||
package appg
|
||||
|
||||
import "time"
|
||||
|
||||
const (
|
||||
defaultShortRecommendRequestTimeout = 3 * time.Second
|
||||
defaultShortRecommendKeyTTLHours = 72
|
||||
)
|
||||
|
||||
// ShortRecommendConfig 控制App侧短视频环形队列读取行为。
|
||||
// Enabled 使用指针是为了兼容旧配置:未配置时默认启用。
|
||||
type ShortRecommendConfig struct {
|
||||
Enabled *bool `json:"enabled"`
|
||||
RequestTimeoutMs int `json:"requestTimeoutMs"`
|
||||
MaxBatches int `json:"maxBatches"`
|
||||
ScanMultiplier int `json:"scanMultiplier"`
|
||||
KeyTTLHours int `json:"keyTTLHours"`
|
||||
}
|
||||
|
||||
func (c *GlobalConfig) ShortRecommendEnabled() bool {
|
||||
return c == nil || c.ShortRecommend.Enabled == nil || *c.ShortRecommend.Enabled
|
||||
}
|
||||
|
||||
func (c *GlobalConfig) ShortRecommendRequestTimeout() time.Duration {
|
||||
if c == nil || c.ShortRecommend.RequestTimeoutMs <= 0 {
|
||||
return defaultShortRecommendRequestTimeout
|
||||
}
|
||||
timeout := time.Duration(c.ShortRecommend.RequestTimeoutMs) * time.Millisecond
|
||||
if timeout < 100*time.Millisecond {
|
||||
return 100 * time.Millisecond
|
||||
}
|
||||
if timeout > 10*time.Second {
|
||||
return 10 * time.Second
|
||||
}
|
||||
return timeout
|
||||
}
|
||||
|
||||
func (c *GlobalConfig) ShortRecommendKeyTTL() int {
|
||||
if c == nil || c.ShortRecommend.KeyTTLHours <= 0 {
|
||||
return defaultShortRecommendKeyTTLHours
|
||||
}
|
||||
return c.ShortRecommend.KeyTTLHours
|
||||
}
|
||||
Reference in New Issue
Block a user