Write reports to operator-selected outputs
This commit is contained in:
@@ -17,7 +17,7 @@ func dailyDefinition() Definition {
|
||||
GeneratedTextSchemaID: "daily",
|
||||
ComparisonStrategy: CompareSameValidDate,
|
||||
ArtifactGroup: "daily",
|
||||
BatchOutputName: "daily.md",
|
||||
OutputName: "daily.md",
|
||||
DistributorPathTemplates: []string{
|
||||
"daily/{valid_start_date}/{run_id}.md",
|
||||
"daily/{valid_start_date}/index.md",
|
||||
|
||||
@@ -42,7 +42,7 @@ type Definition struct {
|
||||
GeneratedTextSchemaID string
|
||||
ComparisonStrategy ComparisonStrategy
|
||||
ArtifactGroup string
|
||||
BatchOutputName string
|
||||
OutputName string
|
||||
DistributorPathTemplates []string
|
||||
CompatiblePriorIDs []ID
|
||||
Modules []module.ConfigItem
|
||||
@@ -52,6 +52,23 @@ type Definition struct {
|
||||
runIDDisambiguator func(Resolved) string
|
||||
}
|
||||
|
||||
func (r Resolved) OutputName() (string, error) {
|
||||
if r.Definition.ID == Daily {
|
||||
if r.ValidPeriod.Start.IsZero() {
|
||||
return "", fmt.Errorf("daily report has no valid-period start for output naming")
|
||||
}
|
||||
location, err := timeutil.LoadLocation(r.Timezone)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("load report timezone for output naming: %w", err)
|
||||
}
|
||||
return "daily-" + r.ValidPeriod.Start.In(location).Format(timeutil.DateLayout) + ".md", nil
|
||||
}
|
||||
if r.Definition.OutputName == "" {
|
||||
return "", fmt.Errorf("report %q has no output name", r.Definition.ID)
|
||||
}
|
||||
return r.Definition.OutputName, nil
|
||||
}
|
||||
|
||||
func (d Definition) ResolvePeriod(req ResolveRequest) (timeutil.Period, error) {
|
||||
if d.resolve == nil {
|
||||
return timeutil.Period{}, fmt.Errorf("report %q has no valid-period resolver", d.ID)
|
||||
|
||||
@@ -19,7 +19,7 @@ func hourlyDefinition() Definition {
|
||||
GeneratedTextSchemaID: "hourly",
|
||||
ComparisonStrategy: CompareRollingWindow,
|
||||
ArtifactGroup: "hourly",
|
||||
BatchOutputName: "hourly.md",
|
||||
OutputName: "hourly.md",
|
||||
DistributorPathTemplates: []string{
|
||||
"hourly/index.md",
|
||||
},
|
||||
|
||||
@@ -103,7 +103,7 @@ func TestRegistryDefinitionsPreserveRetainedContracts(t *testing.T) {
|
||||
for _, tt := range tests {
|
||||
t.Run(string(tt.id), func(t *testing.T) {
|
||||
definition := registry.MustLookup(tt.id)
|
||||
if definition.ComparisonStrategy != tt.comparison || definition.Morning != tt.morning || definition.Evening != tt.evening || definition.BatchOutputName != tt.outputName {
|
||||
if definition.ComparisonStrategy != tt.comparison || definition.Morning != tt.morning || definition.Evening != tt.evening || definition.OutputName != tt.outputName {
|
||||
t.Fatalf("definition = %#v, want retained report contract", definition)
|
||||
}
|
||||
if strings.Join(definition.DistributorPathTemplates, "|") != strings.Join(tt.paths, "|") {
|
||||
|
||||
@@ -15,7 +15,7 @@ func todayDefinition() Definition {
|
||||
GeneratedTextSchemaID: "today",
|
||||
ComparisonStrategy: CompareSameValidDate,
|
||||
ArtifactGroup: "today",
|
||||
BatchOutputName: "today.md",
|
||||
OutputName: "today.md",
|
||||
DistributorPathTemplates: []string{
|
||||
"daily/{valid_start_date}/{run_id}.md",
|
||||
"daily/{valid_start_date}/index.md",
|
||||
|
||||
@@ -15,7 +15,7 @@ func tomorrowDefinition() Definition {
|
||||
GeneratedTextSchemaID: "tomorrow",
|
||||
ComparisonStrategy: CompareSameValidDate,
|
||||
ArtifactGroup: "tomorrow",
|
||||
BatchOutputName: "tomorrow.md",
|
||||
OutputName: "tomorrow.md",
|
||||
DistributorPathTemplates: []string{
|
||||
"daily/{valid_start_date}/{run_id}.md",
|
||||
"daily/{valid_start_date}/index.md",
|
||||
|
||||
Reference in New Issue
Block a user