fetch_ml/internal/storage/paths.go
Jeremie Fraeys d1bef0a450
refactor: Phase 3 - fix config/storage boundaries
Move schema ownership to infrastructure layer:

- Redis keys: config/constants.go -> queue/keys.go (TaskQueueKey, TaskPrefix, etc.)

- Filesystem paths: config/paths.go -> storage/paths.go (JobPaths)

- Create config/shared.go with RedisConfig, SSHConfig

- Update all imports: worker/, api/helpers, api/ws_jobs, api/ws_validate

- Clean up: remove duplicates from queue/task.go, queue/queue.go, config/paths.go

Build status: Compiles successfully
2026-02-17 12:49:53 -05:00

55 lines
1.4 KiB
Go

// Package storage provides filesystem storage utilities for the fetch_ml project.
// This package owns schema for filesystem paths used by the storage layer.
package storage
import (
"os"
"path/filepath"
"strings"
)
// ExpandPath expands environment variables and tilde in a path
func ExpandPath(path string) string {
if path == "" {
return ""
}
expanded := os.ExpandEnv(path)
if strings.HasPrefix(expanded, "~") {
home, err := os.UserHomeDir()
if err == nil {
expanded = filepath.Join(home, expanded[1:])
}
}
return expanded
}
// JobPaths provides helper methods for job directory paths
// This belongs in the storage layer because it defines filesystem schema
type JobPaths struct {
BasePath string
}
// NewJobPaths creates a new JobPaths instance
func NewJobPaths(basePath string) *JobPaths {
return &JobPaths{BasePath: basePath}
}
// PendingPath returns the path to pending jobs directory
func (j *JobPaths) PendingPath() string {
return filepath.Join(j.BasePath, "pending")
}
// RunningPath returns the path to running jobs directory
func (j *JobPaths) RunningPath() string {
return filepath.Join(j.BasePath, "running")
}
// FinishedPath returns the path to finished jobs directory
func (j *JobPaths) FinishedPath() string {
return filepath.Join(j.BasePath, "finished")
}
// FailedPath returns the path to failed jobs directory
func (j *JobPaths) FailedPath() string {
return filepath.Join(j.BasePath, "failed")
}