-
Notifications
You must be signed in to change notification settings - Fork 110
/
env.go
36 lines (31 loc) · 1.18 KB
/
env.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
package utils
import (
"os"
"time"
"go.viam.com/rdk/logging"
)
const (
// DefaultResourceConfigurationTimeout is the default resource configuration
// timeout.
DefaultResourceConfigurationTimeout = time.Minute
// ResourceConfigurationTimeoutEnvVar is the environment variable that can
// be set to override defaultResourceConfigurationTimeout as the duration
// that resources and modules are allowed to (re)configure and startup
// respectively.
ResourceConfigurationTimeoutEnvVar = "VIAM_RESOURCE_CONFIGURATION_TIMEOUT"
)
// GetResourceConfigurationTimeout calculates the resource configuration
// timeout (env variable value if set, defaultResourceConfigurationTimeout
// otherwise).
func GetResourceConfigurationTimeout(logger logging.Logger) time.Duration {
if timeoutVal := os.Getenv(ResourceConfigurationTimeoutEnvVar); timeoutVal != "" {
timeout, err := time.ParseDuration(timeoutVal)
if err != nil {
logger.Warn("Failed to parse %s env var, falling back to default %v timeout",
ResourceConfigurationTimeoutEnvVar, DefaultResourceConfigurationTimeout)
return DefaultResourceConfigurationTimeout
}
return timeout
}
return DefaultResourceConfigurationTimeout
}