mirror of
https://github.com/openfaas/faas.git
synced 2025-06-18 03:56:37 +00:00
Add timeouts and unit test config.
This commit is contained in:
69
watchdog/readconfig.go
Normal file
69
watchdog/readconfig.go
Normal file
@ -0,0 +1,69 @@
|
||||
package main
|
||||
|
||||
import "strconv"
|
||||
|
||||
// HasEnv provides interface for os.Getenv
|
||||
type HasEnv interface {
|
||||
Getenv(key string) string
|
||||
}
|
||||
|
||||
// ReadConfig constitutes config from env variables
|
||||
type ReadConfig struct {
|
||||
}
|
||||
|
||||
func parseBoolValue(val string) bool {
|
||||
if val == "true" {
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func parseIntValue(val string) int {
|
||||
if len(val) > 0 {
|
||||
parsedVal, parseErr := strconv.Atoi(val)
|
||||
|
||||
if parseErr == nil && parsedVal >= 0 {
|
||||
|
||||
return parsedVal
|
||||
}
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
// Read fetches config from environmental variables.
|
||||
func (ReadConfig) Read(hasEnv HasEnv) WatchdogConfig {
|
||||
cfg := WatchdogConfig{
|
||||
writeDebug: true,
|
||||
}
|
||||
|
||||
cfg.faasProcess = hasEnv.Getenv("fprocess")
|
||||
|
||||
readTimeout := parseIntValue(hasEnv.Getenv("read_timeout"))
|
||||
writeTimeout := parseIntValue(hasEnv.Getenv("write_timeout"))
|
||||
|
||||
if readTimeout == 0 {
|
||||
cfg.readTimeout = 5
|
||||
} else {
|
||||
cfg.readTimeout = readTimeout
|
||||
}
|
||||
if writeTimeout == 0 {
|
||||
cfg.writeTimeout = 5
|
||||
} else {
|
||||
cfg.writeTimeout = writeTimeout
|
||||
}
|
||||
|
||||
cfg.writeDebug = parseBoolValue(hasEnv.Getenv("write_debug"))
|
||||
|
||||
return cfg
|
||||
}
|
||||
|
||||
// WatchdogConfig for the process.
|
||||
type WatchdogConfig struct {
|
||||
readTimeout int
|
||||
writeTimeout int
|
||||
// faasProcess is the process to exec
|
||||
faasProcess string
|
||||
|
||||
// writeDebug write console stdout statements to the container
|
||||
writeDebug bool
|
||||
}
|
Reference in New Issue
Block a user