refactor: adopt PathRegistry in experiment manager
Update internal/experiment/manager.go to use centralized PathRegistry: Changes: - Add import for internal/config package - Add NewManagerFromPaths() constructor using PathRegistry - Update Initialize() to use config.FromEnv().ExperimentsDir() with EnsureDir() - Update archiveExperiment() to use PathRegistry pattern Benefits: - Consistent experiment directory location via PathRegistry - Centralized directory creation with EnsureDir() - Backward compatible: existing NewManager() still works - New code can use NewManagerFromPaths() for PathRegistry integration
This commit is contained in:
parent
3e744bf312
commit
2101e4a01c
1 changed files with 17 additions and 1 deletions
|
|
@ -13,6 +13,7 @@ import (
|
|||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/jfraeys/fetch_ml/internal/config"
|
||||
"github.com/jfraeys/fetch_ml/internal/container"
|
||||
"github.com/jfraeys/fetch_ml/internal/fileutil"
|
||||
"github.com/jfraeys/fetch_ml/internal/worker/integrity"
|
||||
|
|
@ -46,6 +47,13 @@ func NewManager(basePath string) *Manager {
|
|||
}
|
||||
}
|
||||
|
||||
// NewManagerFromPaths creates a new experiment manager using PathRegistry.
|
||||
func NewManagerFromPaths(paths *config.PathRegistry) *Manager {
|
||||
return &Manager{
|
||||
basePath: paths.ExperimentsDir(),
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Manager) BasePath() string {
|
||||
if m == nil {
|
||||
return ""
|
||||
|
|
@ -55,7 +63,9 @@ func (m *Manager) BasePath() string {
|
|||
|
||||
// Initialize ensures the experiment directory exists
|
||||
func (m *Manager) Initialize() error {
|
||||
if err := os.MkdirAll(m.basePath, 0o750); err != nil {
|
||||
// Use PathRegistry for consistent path management
|
||||
paths := config.FromEnv()
|
||||
if err := paths.EnsureDir(paths.ExperimentsDir()); err != nil {
|
||||
return fmt.Errorf("failed to create experiment base directory: %w", err)
|
||||
}
|
||||
return nil
|
||||
|
|
@ -220,6 +230,12 @@ func (m *Manager) archiveExperiment(commitID string) (string, error) {
|
|||
|
||||
stamp := time.Now().UTC().Format("20060102-150405")
|
||||
archiveRoot := filepath.Join(m.basePath, "archive", stamp)
|
||||
|
||||
// Use PathRegistry pattern for directory creation
|
||||
paths := config.FromEnv()
|
||||
if err := paths.EnsureDir(filepath.Join(paths.ExperimentsDir(), "archive")); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := os.MkdirAll(archiveRoot, 0o750); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue