Config: Improve Config.WakeupInterval() and add tests
This commit is contained in:
parent
b545c92be9
commit
74b2b03d94
4 changed files with 23 additions and 7 deletions
|
@ -55,7 +55,7 @@ func init() {
|
|||
TotalMem = memory.TotalMemory()
|
||||
|
||||
// Check available memory if not running in unsafe mode.
|
||||
if os.Getenv("PHOTOPRISM_UNSAFE") == "" {
|
||||
if Env(EnvUnsafe) {
|
||||
// Disable features with high memory requirements?
|
||||
LowMem = TotalMem < MinMem
|
||||
}
|
||||
|
@ -594,12 +594,18 @@ func (c *Config) WakeupInterval() time.Duration {
|
|||
// Default to 15 minutes if no interval is set.
|
||||
return DefaultWakeupInterval
|
||||
}
|
||||
} else if c.options.WakeupInterval > MaxWakeupInterval {
|
||||
// Do not run less than once per day.
|
||||
return MaxWakeupInterval
|
||||
} else if c.options.WakeupInterval < MinWakeupInterval {
|
||||
// Do not run more than once per minute.
|
||||
}
|
||||
|
||||
// Do not run more than once per minute.
|
||||
if c.options.WakeupInterval < MinWakeupInterval/time.Second {
|
||||
return MinWakeupInterval
|
||||
} else if c.options.WakeupInterval < MinWakeupInterval {
|
||||
c.options.WakeupInterval = c.options.WakeupInterval * time.Second
|
||||
}
|
||||
|
||||
// Do not run less than once per day.
|
||||
if c.options.WakeupInterval > MaxWakeupInterval {
|
||||
return MaxWakeupInterval
|
||||
}
|
||||
|
||||
return c.options.WakeupInterval
|
||||
|
|
|
@ -285,6 +285,15 @@ func TestConfig_Workers(t *testing.T) {
|
|||
|
||||
func TestConfig_WakeupInterval(t *testing.T) {
|
||||
c := NewConfig(CliTestContext())
|
||||
i := c.WakeupInterval()
|
||||
assert.Equal(t, "1h34m9s", c.WakeupInterval().String())
|
||||
c.options.WakeupInterval = 45
|
||||
assert.Equal(t, "1m0s", c.WakeupInterval().String())
|
||||
c.options.WakeupInterval = 0
|
||||
assert.Equal(t, "15m0s", c.WakeupInterval().String())
|
||||
c.options.WakeupInterval = 150
|
||||
assert.Equal(t, "2m30s", c.WakeupInterval().String())
|
||||
c.options.WakeupInterval = i
|
||||
assert.Equal(t, "1h34m9s", c.WakeupInterval().String())
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
|
||||
// Environment names.
|
||||
const (
|
||||
EnvUnsafe = "unsafe"
|
||||
EnvDebug = "debug"
|
||||
EnvTrace = "trace"
|
||||
EnvDemo = "demo"
|
||||
|
|
|
@ -64,7 +64,7 @@ var Flags = CliFlags{
|
|||
Flag: cli.BoolFlag{
|
||||
Name: "unsafe",
|
||||
Hidden: true,
|
||||
Usage: "enable unsafe mode",
|
||||
Usage: "disable safety checks",
|
||||
EnvVar: "PHOTOPRISM_UNSAFE",
|
||||
}},
|
||||
CliFlag{
|
||||
|
|
Loading…
Reference in a new issue