diff --git a/internal/manager/config/config.go b/internal/manager/config/config.go index 54177e81..ae0ea3e8 100644 --- a/internal/manager/config/config.go +++ b/internal/manager/config/config.go @@ -23,6 +23,7 @@ import ( "projects.blender.org/studio/flamenco/internal/appinfo" "projects.blender.org/studio/flamenco/internal/manager/eventbus" "projects.blender.org/studio/flamenco/pkg/crosspath" + "projects.blender.org/studio/flamenco/pkg/duration" shaman_config "projects.blender.org/studio/flamenco/pkg/shaman/config" ) @@ -75,8 +76,8 @@ type Base struct { ManagerName string `yaml:"manager_name"` - DatabaseDSN string `yaml:"database"` - DBIntegrityCheck Duration `yaml:"database_check_period"` + DatabaseDSN string `yaml:"database"` + DBIntegrityCheck duration.Duration `yaml:"database_check_period"` Listen string `yaml:"listen"` @@ -92,8 +93,8 @@ type Base struct { Shaman shaman_config.Config `yaml:"shaman"` - TaskTimeout Duration `yaml:"task_timeout"` - WorkerTimeout Duration `yaml:"worker_timeout"` + TaskTimeout duration.Duration `yaml:"task_timeout"` + WorkerTimeout duration.Duration `yaml:"worker_timeout"` /* This many failures (on a given job+task type combination) will ban a worker * from that task type on that job. */ diff --git a/internal/manager/config/defaults.go b/internal/manager/config/defaults.go index 1b607fc3..e4030b5e 100644 --- a/internal/manager/config/defaults.go +++ b/internal/manager/config/defaults.go @@ -5,6 +5,7 @@ import ( "time" "projects.blender.org/studio/flamenco/internal/manager/eventbus" + "projects.blender.org/studio/flamenco/pkg/duration" shaman_config "projects.blender.org/studio/flamenco/pkg/shaman/config" ) @@ -20,7 +21,7 @@ var defaultConfig = Conf{ ManagerName: "Flamenco", Listen: ":8080", DatabaseDSN: "flamenco-manager.sqlite", - DBIntegrityCheck: Duration(10 * time.Minute), + DBIntegrityCheck: duration.Duration(10 * time.Minute), SSDPDiscovery: true, LocalManagerStoragePath: "./flamenco-manager-storage", SharedStoragePath: "", // Empty string means "first run", and should trigger the config setup assistant. @@ -29,13 +30,13 @@ var defaultConfig = Conf{ // Enable Shaman by default, except on Windows where symlinks are still tricky. Enabled: runtime.GOOS != "windows", GarbageCollect: shaman_config.GarbageCollect{ - Period: 24 * time.Hour, - MaxAge: 31 * 24 * time.Hour, + Period: duration.Duration(24 * time.Hour), + MaxAge: duration.Duration(31 * 24 * time.Hour), }, }, - TaskTimeout: Duration(10 * time.Minute), - WorkerTimeout: Duration(1 * time.Minute), + TaskTimeout: duration.Duration(10 * time.Minute), + WorkerTimeout: duration.Duration(1 * time.Minute), BlocklistThreshold: 3, TaskFailAfterSoftFailCount: 3, diff --git a/internal/manager/config/time_duration.go b/pkg/duration/time_duration.go similarity index 98% rename from internal/manager/config/time_duration.go rename to pkg/duration/time_duration.go index ab762dc5..8f30f8dc 100644 --- a/internal/manager/config/time_duration.go +++ b/pkg/duration/time_duration.go @@ -1,4 +1,4 @@ -package config +package duration // SPDX-License-Identifier: GPL-3.0-or-later diff --git a/internal/manager/config/time_duration_test.go b/pkg/duration/time_duration_test.go similarity index 99% rename from internal/manager/config/time_duration_test.go rename to pkg/duration/time_duration_test.go index 54863d59..fb7494ab 100644 --- a/internal/manager/config/time_duration_test.go +++ b/pkg/duration/time_duration_test.go @@ -1,4 +1,4 @@ -package config +package duration // SPDX-License-Identifier: GPL-3.0-or-later diff --git a/pkg/shaman/cleanup.go b/pkg/shaman/cleanup.go index 0316a0a4..f11f3e55 100644 --- a/pkg/shaman/cleanup.go +++ b/pkg/shaman/cleanup.go @@ -57,13 +57,13 @@ func (s *Server) periodicCleanup() { select { case <-s.shutdownChan: return - case <-time.After(s.config.GarbageCollect.Period): + case <-time.After(time.Duration(s.config.GarbageCollect.Period)): } } } func (s *Server) gcAgeThreshold() time.Time { - return time.Now().Add(-s.config.GarbageCollect.MaxAge).Round(1 * time.Second) + return time.Now().Add(time.Duration(-s.config.GarbageCollect.MaxAge).Round(1 * time.Second)) } diff --git a/pkg/shaman/cleanup_test.go b/pkg/shaman/cleanup_test.go index cdb4bbe4..2b396fbb 100644 --- a/pkg/shaman/cleanup_test.go +++ b/pkg/shaman/cleanup_test.go @@ -58,7 +58,7 @@ func makeOld(shaman *Server, expectOld mtimeMap, relPath string) { shaman.config.GarbageCollect.MaxAge)) } age := -2 * shaman.config.GarbageCollect.MaxAge - oldTime := time.Now().Add(age) + oldTime := time.Now().Add(time.Duration(age)) absPath := filepath.Join(shaman.config.FileStorePath(), relPath) err := os.Chtimes(absPath, oldTime, oldTime) @@ -76,7 +76,7 @@ func makeOld(shaman *Server, expectOld mtimeMap, relPath string) { log.Debug(). Str("relPath", relPath). - Stringer("age", age). + Stringer("age", time.Duration(age)). Stringer("stamp", oldTime). Stringer("actual", osModTime). Msg("makeOld") @@ -93,7 +93,7 @@ func TestGCCanary(t *testing.T) { server, cleanup := createTestShaman() defer cleanup() - assert.True(t, server.config.GarbageCollect.MaxAge > 10*time.Minute, + assert.True(t, time.Duration(server.config.GarbageCollect.MaxAge) > 10*time.Minute, "config.GarbageCollect.MaxAge must be big enough for this test to be reliable, is %v", server.config.GarbageCollect.MaxAge) } diff --git a/pkg/shaman/config/config.go b/pkg/shaman/config/config.go index 71a5d908..680a7f47 100644 --- a/pkg/shaman/config/config.go +++ b/pkg/shaman/config/config.go @@ -24,7 +24,8 @@ package config import ( "path/filepath" - "time" + + "projects.blender.org/studio/flamenco/pkg/duration" ) const ( @@ -52,9 +53,9 @@ type Config struct { // GarbageCollect contains the config options for the GC. type GarbageCollect struct { // How frequently garbage collection is performed on the file store: - Period time.Duration `yaml:"period"` + Period duration.Duration `yaml:"period"` // How old files must be before they are GC'd: - MaxAge time.Duration `yaml:"maxAge"` + MaxAge duration.Duration `yaml:"maxAge"` // Used by the -gc CLI arg to silently disable the garbage collector // while we're performing a manual sweep. diff --git a/pkg/shaman/config/testing.go b/pkg/shaman/config/testing.go index 95aeedd6..1667ec31 100644 --- a/pkg/shaman/config/testing.go +++ b/pkg/shaman/config/testing.go @@ -26,6 +26,8 @@ import ( "os" "path/filepath" "time" + + "projects.blender.org/studio/flamenco/pkg/duration" ) // CreateTestConfig creates a configuration + cleanup function. @@ -46,8 +48,8 @@ func CreateTestConfig() (conf Config, cleanup func()) { StoragePath: tempDir, GarbageCollect: GarbageCollect{ - Period: 8 * time.Hour, - MaxAge: 31 * 24 * time.Hour, + Period: duration.Duration(8 * time.Hour), + MaxAge: duration.Duration(31 * 24 * time.Hour), }, }