Add service status and usage dashboard, refresh externally published edits

This commit is contained in:
2026-10-09 20:20:44 +01:00
parent 67ac79765f
commit a50e8648f6
31 changed files with 1283 additions and 42 deletions
+56
View File
@@ -19,6 +19,7 @@ import (
"git.a-wan.net/alan/pipelines/internal/pipeline"
"git.a-wan.net/alan/pipelines/internal/protocol"
"git.a-wan.net/alan/pipelines/internal/runinspect"
"git.a-wan.net/alan/pipelines/internal/statusview"
"git.a-wan.net/alan/pipelines/internal/tui"
tea "github.com/charmbracelet/bubbletea"
)
@@ -238,6 +239,17 @@ func (a App) Run(ctx context.Context, args []string) error {
c, err := client.Open(dialCtx, o.url)
cancel()
if err != nil {
if command == "status" && len(pos) == 0 {
s := statusview.Offline(o.url)
if o.json {
if outputErr := a.output(s); outputErr != nil {
return outputErr
}
} else {
fmt.Fprintln(a.Out, strings.Join(statusview.Lines(s), "\n"))
}
return fmt.Errorf("Pipelines server unavailable")
}
return err
}
defer c.Close()
@@ -272,6 +284,50 @@ func (a App) Run(ctx context.Context, args []string) error {
return pos[0], nil
}
switch command {
case "stats":
if len(pos) != 0 {
return fmt.Errorf("stats takes no arguments")
}
response, err := call(protocol.Message{Type: protocol.ListRuns})
if err != nil {
return err
}
if response.Usage == nil {
return fmt.Errorf("server did not return usage statistics; update pipelines-server")
}
if o.json {
return a.output(response.Usage)
}
u := response.Usage
average := "—"
if u.Total > u.Active {
average = time.Duration(u.AverageSeconds * float64(time.Second)).Round(time.Second).String()
}
fmt.Fprintf(a.Out, "Usage · all history\n%d runs · %d succeeded · %d failed · %d canceled · %d interrupted · %d active\nAverage completed duration: %s\n\nPipeline\tRuns\tSucceeded\tFailed\tActive\n", u.Total, u.Succeeded, u.Failed, u.Canceled, u.Interrupted, u.Active, average)
for _, p := range u.Pipelines {
fmt.Fprintf(a.Out, "%s\t%d\t%d\t%d\t%d\n", p.Name, p.Total, p.Succeeded, p.Failed, p.Active)
}
fmt.Fprintln(a.Out, "\nDaily activity (UTC)")
for _, d := range u.Days {
fmt.Fprintf(a.Out, "%s\t%d\n", d.Date, d.Runs)
}
return nil
case "status":
if len(pos) != 0 {
return fmt.Errorf("status takes no arguments")
}
response, err := call(protocol.Message{Type: protocol.GetStatus})
if err != nil {
return err
}
if response.Status == nil {
return fmt.Errorf("server did not return status; update pipelines-server")
}
if o.json {
return a.output(response.Status)
}
_, err = fmt.Fprintln(a.Out, strings.Join(statusview.Lines(response.Status), "\n"))
return err
case "debug":
value, err := one()
if err != nil {