forked from roadrunner-server/roadrunner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
51 lines (40 loc) · 1.34 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package roadrunner
import (
"fmt"
"time"
)
// Config defines basic behaviour of worker creation and handling process.
type Config struct {
// NumWorkers defines how many sub-processes can be run at once. This value
// might be doubled by Swapper while hot-swap.
NumWorkers int64
// MaxJobs defines how many executions is allowed for the worker until
// it's destruction. set 1 to create new process for each new task, 0 to let
// worker handle as many tasks as it can.
MaxJobs int64
// AllocateTimeout defines for how long pool will be waiting for a worker to
// be freed to handle the task.
AllocateTimeout time.Duration
// DestroyTimeout defines for how long pool should be waiting for worker to
// properly stop, if timeout reached worker will be killed.
DestroyTimeout time.Duration
}
// InitDefaults allows to init blank config with pre-defined set of default values.
func (cfg *Config) InitDefaults() error {
cfg.AllocateTimeout = time.Minute
cfg.DestroyTimeout = time.Minute
return nil
}
// Valid returns error if config not valid.
func (cfg *Config) Valid() error {
if cfg.NumWorkers == 0 {
return fmt.Errorf("pool.NumWorkers must be set")
}
if cfg.AllocateTimeout == 0 {
return fmt.Errorf("pool.AllocateTimeout must be set")
}
if cfg.DestroyTimeout == 0 {
return fmt.Errorf("pool.DestroyTimeout must be set")
}
return nil
}