-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsettings.go
67 lines (58 loc) · 1.92 KB
/
settings.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package komi
import (
"github.com/charmbracelet/log"
)
// Settings is an internal struct that tunes the pool as requested.
type Settings struct {
// Laborers is the number of laborers (work performers) that should
// run in parallel.
Laborers int
// Size sets the Size of the pool, or how many inputs and outputs (each
// has separate Size) can be set by the pool. If Size is reached, submissions
// or work results will be blocked.
Size int
// sizeOverride is true if the user chose to set the size manually, instead of
// letting the pool set it automatically.
sizeOverride bool
// Ratio is the ratio that is used (unless size is set manually)
// for setting the size to the number of laborers.
Ratio int
// Debug will set the logger to show all Debug logs too.
Debug bool
// Name is the Name of the pool.
Name string
// LogLevel defaults to warn, can be set by the user.
LogLevel log.Level
}
// verifySettings will make sure the settings are proper and
// set sensible defaults if user hasn't set them manually.
func verifySettings(settings *Settings) {
// If laborers have not been set, default to number of CPUs.
if settings.Laborers <= 0 {
settings.Laborers = defaultNumLaborers
}
// If the user has manually set the size, that shall be used.
if settings.Size > 0 {
settings.sizeOverride = true
}
// If ratio is default, set the default size ratio.
if settings.Ratio <= 0 {
settings.Ratio = defaultRatio
}
// If size has not been manually set, default to `size = ratio * laborers`
if !settings.sizeOverride {
settings.Size = settings.Ratio * settings.Laborers
}
// If log level is default, set it to at least to warn level.
if settings.LogLevel <= 0 {
settings.LogLevel = log.WarnLevel
}
// If debug is set, set the log level to debug.
if settings.Debug {
settings.LogLevel = log.DebugLevel
}
// If name is empty, set it to default.
if len(settings.Name) < 1 {
settings.Name = defaultName
}
}