65fdcbc789
Ingest sweeps reported outcome only to the log: a failing sweep, or one that silently no-ops because its env config is missing, was invisible from the CLI/MCP surface. Extend the (previously dead) sources registry table with per-source sweep state and expose it. - db: RecordSync upserts one outcome per sweep (status ok/error/unconfigured, timestamps kept monotonic, last success survives a later failure); the columns are declared in schema.sql and added by migration for existing DBs. - db: SourceSync reads sweep state joined with derived per-source counts from observations, and computes a verdict: ok, stale (>2.5x interval since last success), error, unconfigured, never. - watch: record every sweep of browser-history, gitea, git, opencode-session, karakeep, bookorbit and brevier — including failures and not-configured no-ops, which are exactly the invisible cases. - cmd: knox sync-status [--json] and the knox_sync_status MCP tool. Motivating case: this node's watch container has no KARAKEEP_URL/API_KEY, so its karakeep ingester was a permanent silent no-op.
56 lines
1.6 KiB
Go
56 lines
1.6 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/david/knox/internal/db"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// NewSyncStatusCmd reports per-source ingest sync health: the watcher's last
|
|
// sweep per source (success/error/not-configured), how stale it is relative to
|
|
// its interval, and the derived entry counts.
|
|
func NewSyncStatusCmd(kdb *db.KnoxDB) *cobra.Command {
|
|
var jsonOut bool
|
|
cmd := &cobra.Command{
|
|
Use: "sync-status",
|
|
Short: "Show per-source ingest sync health",
|
|
RunE: func(c *cobra.Command, args []string) error {
|
|
rows, err := kdb.SourceSync()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if jsonOut {
|
|
b, _ := json.MarshalIndent(rows, "", " ")
|
|
fmt.Println(string(b))
|
|
return nil
|
|
}
|
|
now := time.Now().UTC()
|
|
fmt.Printf("%-18s %-13s %8s %-10s %-9s %s\n", "SOURCE", "STATUS", "ENTRIES", "LAST OK", "INTERVAL", "LAST ERROR")
|
|
for _, r := range rows {
|
|
lastOK := "never"
|
|
if r.LastSuccess != "" {
|
|
lastOK = db.RelTime(now, db.ParseRFC3339(r.LastSuccess)) + " ago"
|
|
}
|
|
interval := "-"
|
|
if r.IntervalSeconds > 0 {
|
|
interval = (time.Duration(r.IntervalSeconds) * time.Second).String()
|
|
}
|
|
lastErr := r.LastErrorDetail
|
|
if len(lastErr) > 50 {
|
|
lastErr = lastErr[:50] + "…"
|
|
}
|
|
fmt.Printf("%-18s %-13s %8d %-10s %-9s %s\n", r.ID, r.Status, r.Entries, lastOK, interval, lastErr)
|
|
}
|
|
fmt.Println()
|
|
fmt.Println("ok = swept on schedule; stale = last success overdue; never = no sweep recorded;")
|
|
fmt.Println("unconfigured = source env missing, sweep is a no-op.")
|
|
return nil
|
|
},
|
|
}
|
|
cmd.Flags().BoolVar(&jsonOut, "json", false, "Output as JSON")
|
|
return cmd
|
|
}
|