Refactoring complete: v0.4.0 architectural milestone (#1)
## Summary Completed Phase 5 refactoring and reached the target architecture. **Architectural milestone achieved:** - Service layer owns all state and is the sole writer - UI is a thin Fyne view, all widget updates marshaled via `fyne.Do` - Core engines are stateless and injectable - Domain types are pure (no `yaml:"-"` fields) - Full module builds and `go vet ./...` clean ## Changes - Bump version: 0.3.6 → 0.4.0 - Update CHANGELOG with Phase 5 summary - Add ROADMAP "Refactoring Follow-Ups" section ## Known follow-up work 1. **Linux test build broken** — `runner_test.go` needs `//go:build windows` tag 2. **File-size limits exceeded** — `operations.go` (486 lines), `jobs_view.go` (415 lines) See ROADMAP.md for details. --------- Co-authored-by: mixeme <mix.public@ya.ru> Reviewed-on: #1
This commit was merged in pull request #1.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
package runner
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func CleanupLogs(logsDir string, maxFiles int, maxAgeDays int) error {
|
||||
entries, err := os.ReadDir(logsDir)
|
||||
if err != nil {
|
||||
if errors.Is(err, os.ErrNotExist) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
type logFile struct {
|
||||
path string
|
||||
modTime time.Time
|
||||
}
|
||||
var logs []logFile
|
||||
cutoff := time.Now().AddDate(0, 0, -maxAgeDays)
|
||||
for _, entry := range entries {
|
||||
// Only GoSentry run logs are managed here. Directories and non-.log files
|
||||
// are intentionally ignored so the user can keep notes or other artifacts
|
||||
// in the same folder without the cleanup policy deleting them.
|
||||
if entry.IsDir() || !strings.HasSuffix(strings.ToLower(entry.Name()), ".log") {
|
||||
continue
|
||||
}
|
||||
path := filepath.Join(logsDir, entry.Name())
|
||||
info, err := entry.Info()
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if maxAgeDays > 0 && info.ModTime().Before(cutoff) {
|
||||
// Cleanup is best-effort: failing to delete one file should not block
|
||||
// the scheduler from running future jobs.
|
||||
_ = os.Remove(path)
|
||||
continue
|
||||
}
|
||||
logs = append(logs, logFile{path: path, modTime: info.ModTime()})
|
||||
}
|
||||
|
||||
if maxFiles <= 0 || len(logs) <= maxFiles {
|
||||
return nil
|
||||
}
|
||||
sort.Slice(logs, func(i int, j int) bool {
|
||||
// Newest files are kept first, then everything after maxFiles is removed.
|
||||
// This matches the user's expectation that the most recent failures and
|
||||
// command output remain available for investigation.
|
||||
return logs[i].modTime.After(logs[j].modTime)
|
||||
})
|
||||
for _, old := range logs[maxFiles:] {
|
||||
_ = os.Remove(old.path)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user