Browse Source

En cours de développement

master
losyme 4 months ago
parent
commit
1c61fa3e13
  1. 34
      workers/config.go
  2. 12
      workers/workers.go

34
workers/config.go

@ -30,39 +30,19 @@ type Config struct {
Logger Logger
}
type ConfigOption func(*Config)
func WithPoolSize(poolSize int) ConfigOption {
return func(c *Config) {
c.PoolSize = poolSize
}
}
func WithModel(model sdk.Model) ConfigOption {
return func(c *Config) {
c.Model = model
}
}
func WithRunner(runner sdk.Runner) ConfigOption {
return func(c *Config) {
c.Runner = runner
}
}
func WithLogger(logger Logger) ConfigOption {
return func(c *Config) {
c.Logger = logger
}
}
func (c *Config) validate() error {
if c.PoolSize < 0 {
if c.PoolSize == 0 {
c.PoolSize = _defaultPoolSize
} else if c.PoolSize < 0 {
c.PoolSize = 0
} else if c.PoolSize > _maxPoolSize {
c.PoolSize = _maxPoolSize
}
if c.Model == nil {
return errors.New("field 'Model' cannot be nil") ///////////////////////////////////////////////////////////////
}
if c.Runner == nil {
return errors.New("field 'Runner' cannot be nil") //////////////////////////////////////////////////////////////
}

12
workers/workers.go

@ -11,18 +11,6 @@ type Workers struct {
supervisor *supervisor
}
func New(options ...ConfigOption) (*Workers, error) {
cfg := &Config{
PoolSize: _defaultPoolSize,
}
for _, option := range options {
option(cfg)
}
return cfg.BuildWorkers()
}
func (ws *Workers) Start() {
ws.supervisor.start()
}

Loading…
Cancel
Save