Also use our Duration in pkg/shaman (#104408)

Move the `Duration` struct from `internal/manager/config` to
`pkg/duration` so that it can be used by `pkg/shaman` as well.

Reviewed-on: https://projects.blender.org/studio/flamenco/pulls/104408
This commit is contained in:
Vivian Leung 2025-07-11 16:41:41 +02:00 committed by Sybren A. Stüvel
parent 4a0c7b21db
commit 7e40e1bbb0
8 changed files with 26 additions and 21 deletions

View File

@ -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. */

View File

@ -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,

View File

@ -1,4 +1,4 @@
package config
package duration
// SPDX-License-Identifier: GPL-3.0-or-later

View File

@ -1,4 +1,4 @@
package config
package duration
// SPDX-License-Identifier: GPL-3.0-or-later

View File

@ -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))
}

View File

@ -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)
}

View File

@ -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.

View File

@ -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),
},
}