The Web UI and messaging channels now read and write Archie's runtime settings through one versioned, audited control-plane API hosted on the State Store's existing gRPC server: catalog, query, command, watch. Each feature owns its resource, validation and commands; storage only writes versions and audit records. Workflows move with it. Definitions become portable YAML compiled through a closed, typed step registry and stored as a control-plane resource, so the yaegi interpretation paths (internal/gate, wfeval, wfextract, gateeval, gateextract, skillbuild) are deleted rather than carried. The UI process reads definitions as data: the JSON projection lives in internal/domain/workflow/task so a dashboard decodes the stored collection without linking the workflow engine, which cmd/archie-ui's deletion gate forbids. Shipped definitions ride the catalog descriptor rather than a bespoke REST route, keeping the API to its four operations. archie-messaging gains -state-store-target/-state-store-token and reads channel settings from the database, failing closed when the State Store is unreachable: the database is authoritative for those settings.
75 lines
1.8 KiB
Go
75 lines
1.8 KiB
Go
package controlplane
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"github.com/samcharles93/archie-core/internal/config"
|
|
"github.com/samcharles93/archie-core/internal/domain/scheduling"
|
|
"github.com/samcharles93/archie-core/internal/infrastructure/cronstore"
|
|
)
|
|
|
|
const SchedulesKind = "schedules"
|
|
|
|
func scheduleDefinition() Definition {
|
|
return Definition{
|
|
Kind: SchedulesKind,
|
|
Title: "Schedules",
|
|
Schema: arraySchema,
|
|
ApplyMode: "live",
|
|
Seed: func(config.Config) any { return []cronstore.JobSpec{} },
|
|
Validate: func(input []byte) error {
|
|
return validateAs(input, validateSchedules)
|
|
},
|
|
Normalize: normalizeSchedules,
|
|
}
|
|
}
|
|
|
|
func validateSchedules(jobs []cronstore.JobSpec) error {
|
|
seen := make(map[string]struct{}, len(jobs))
|
|
for _, job := range jobs {
|
|
if strings.TrimSpace(job.ID) == "" {
|
|
return fmt.Errorf("schedule ID is required")
|
|
}
|
|
if _, exists := seen[job.ID]; exists {
|
|
return fmt.Errorf("duplicate schedule %q", job.ID)
|
|
}
|
|
seen[job.ID] = struct{}{}
|
|
if job.Kind != cronstore.KindWorkflow {
|
|
return fmt.Errorf("schedule %q has unsupported kind %q", job.ID, job.Kind)
|
|
}
|
|
if err := job.Schedule.Validate(); err != nil {
|
|
return err
|
|
}
|
|
if err := scheduling.Pool(job.Pool).Validate(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func normalizeSchedules(input []byte) ([]byte, error) {
|
|
var jobs []cronstore.JobSpec
|
|
if err := json.Unmarshal(input, &jobs); err != nil {
|
|
return nil, err
|
|
}
|
|
now := time.Now().UTC()
|
|
for i := range jobs {
|
|
jobs[i].Schedule = jobs[i].Schedule.Resolved()
|
|
if jobs[i].NextRun.IsZero() {
|
|
next, err := jobs[i].Schedule.FirstRun(now)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
jobs[i].NextRun = next.UTC()
|
|
}
|
|
if jobs[i].Created.IsZero() {
|
|
jobs[i].Created = now
|
|
}
|
|
jobs[i].Updated = now
|
|
}
|
|
return json.Marshal(jobs)
|
|
}
|