Centralize report path policy

This commit is contained in:
2026-05-29 20:28:06 +00:00
parent 6915bf1ba2
commit 7dc2ac9253
7 changed files with 140 additions and 64 deletions

View File

@@ -6,7 +6,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"time"
"gitea.maximumdirect.net/eric/weatherreporter/internal/adapters/scriptorium"
@@ -157,7 +156,7 @@ func Generate(ctx context.Context, req GenerateRequest) error {
if err != nil {
return err
}
if isGeneratedReport(resolved.Definition.ID) {
if resolved.Definition.Generated {
_, err := GenerateReport(ctx, ReportRequest{
Config: req.Config,
Resolved: resolved,
@@ -200,7 +199,7 @@ func RunBatchDetailed(ctx context.Context, req BatchRequest) (*BatchResult, erro
startedAt := now
result := &BatchResult{Batch: req.Batch, StartedAt: startedAt}
for _, resolved := range resolvedReports {
if !isGeneratedReport(resolved.Definition.ID) {
if !resolved.Definition.Generated {
return nil, fmt.Errorf("run is not implemented")
}
}
@@ -257,19 +256,10 @@ func batchReportResult(resolved report.Resolved) BatchReportResult {
}
func batchOutputPath(outputDir string, definition report.Definition) string {
if outputDir == "" || definition.DefaultOutputName == "" {
if outputDir == "" || definition.BatchOutputName == "" {
return ""
}
name := strings.ReplaceAll(definition.DefaultOutputName, "_", "-")
return filepath.Join(outputDir, name)
}
func isGeneratedReport(id report.ID) bool {
return isDailyReport(id) || id == report.ThreeDay || id == report.Weekend || id == report.Storm
}
func isDailyReport(id report.ID) bool {
return id == report.DailyToday || id == report.DailyTomorrow
return filepath.Join(outputDir, definition.BatchOutputName)
}
func ResolveGenerate(req GenerateRequest, now time.Time) (report.Resolved, error) {