add config

This commit is contained in:
wd665544 2022-07-24 17:34:04 +08:00 committed by Gaius
parent 9cb3417986
commit 1880429e73
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
2 changed files with 26 additions and 0 deletions

View File

@ -81,6 +81,9 @@ func New() *Config {
HostGCInterval: DefaultSchedulerHostGCInterval, HostGCInterval: DefaultSchedulerHostGCInterval,
HostTTL: DefaultSchedulerHostTTL, HostTTL: DefaultSchedulerHostTTL,
}, },
Cpu: DefaultCpu,
RefreshMode: false,
RefreshModelInterval: DefaultRefreshModelInterval,
}, },
DynConfig: &DynConfig{ DynConfig: &DynConfig{
RefreshInterval: DefaultDynConfigRefreshInterval, RefreshInterval: DefaultDynConfigRefreshInterval,
@ -172,6 +175,14 @@ func (cfg *Config) Validate() error {
return errors.New("scheduler requires parameter taskTTL") return errors.New("scheduler requires parameter taskTTL")
} }
if cfg.Scheduler.Cpu <= 0 {
return errors.New("scheduler requires parameter cpu")
}
if cfg.Scheduler.RefreshMode && cfg.Scheduler.RefreshModelInterval <= 0 {
return errors.New("scheduler requires parameter RefreshModelInterval")
}
if cfg.DynConfig.RefreshInterval <= 0 { if cfg.DynConfig.RefreshInterval <= 0 {
return errors.New("dynconfig requires parameter refreshInterval") return errors.New("dynconfig requires parameter refreshInterval")
} }
@ -284,6 +295,15 @@ type SchedulerConfig struct {
// Task and peer gc configuration. // Task and peer gc configuration.
GC *GCConfig `yaml:"gc" mapstructure:"gc"` GC *GCConfig `yaml:"gc" mapstructure:"gc"`
// Cpu Limit
Cpu int `yaml:"cpu" mapstructure:"cpu"`
// Enable refresh mode
RefreshMode bool `yaml:"refreshMode" mapstructure:"refreshMode"`
// Update model interval
RefreshModelInterval time.Duration `yaml:"refreshModelInterval" mapstructure:"refreshModelInterval"`
} }
type GCConfig struct { type GCConfig struct {

View File

@ -76,6 +76,12 @@ const (
// DefaultSchedulerHostTTL is default ttl for host. // DefaultSchedulerHostTTL is default ttl for host.
DefaultSchedulerHostTTL = 48 * time.Hour DefaultSchedulerHostTTL = 48 * time.Hour
// DefaultCPU is default cpu usage
DefaultCpu = 1
// DefaultRefreshModelInterval is model refresh interval
DefaultRefreshModelInterval = 168 * time.Hour
) )
const ( const (