Commit 57ccc40

Eric Bower  ·  2026-05-08 20:16:53 -0400 EDT
parent 97d87a6
chore: copy changes
2 files changed,  +22, -5
+21, -5
......@@ -54,6 +54,7 @@ type Cfg struct {
5454 Event string // event JSON passed via --event flag
5555 EventSource io.ReadCloser // when set, used directly as the event source (for testing)
5656 MonitorInterval time.Duration
57+ GCInterval time.Duration
5758 NewWorkspace WorkspaceFactory
5859 StatusOutput io.Writer // where status JSONL is written (default: os.Stdout)
5960 IncludeRunning bool // emit running status updates in addition to terminal
......@@ -73,12 +74,14 @@ type Event struct {
7374 func NewCfg() (*Cfg, string, bool) {
7475 var keyLoc, certLoc, artifactDir, event string
7576 var monitorInterval time.Duration
77+ var gcInterval time.Duration
7678 var logLevel string
7779 flag.StringVar(&keyLoc, "pk", "", "ssh private key used to authenticate with pico services")
7880 flag.StringVar(&certLoc, "ck", "", "ssh certificate public key used to authenticate with pico services (only required if using ssh certificates)")
7981 flag.StringVar(&artifactDir, "artifact-dir", "/tmp/pici-artifacts", "local directory to stage artifacts")
8082 flag.StringVar(&event, "event", "", "event JSON to run (alternative to reading from stdin)")
8183 flag.DurationVar(&monitorInterval, "monitor-interval", 5*time.Second, "interval for monitoring zmx sessions")
84+ flag.DurationVar(&gcInterval, "gc-interval", 10*time.Minute, "interval for garbage collection in monitor (0 to disable)")
8285 flag.StringVar(&logLevel, "log-level", "info", "log level: debug, info, warn, error")
8386 var includeRunning bool
8487 var human bool
......@@ -107,6 +110,7 @@ func NewCfg() (*Cfg, string, bool) {
107110 ArtifactDir: artifactDir,
108111 Event: event,
109112 MonitorInterval: monitorInterval,
113+ GCInterval: gcInterval,
110114 IncludeRunning: includeRunning,
111115 HumanOutput: human,
112116 Wait: wait,
......@@ -226,6 +230,7 @@ FLAGS
226230 -ck <path> SSH certificate public key
227231 -artifact-dir <path> Local directory to stage artifacts (default: /tmp/pici-artifacts)
228232 -monitor-interval <dur> Poll interval (default: 5s)
233+ -gc-interval <dur> Garbage collection interval (default: 10m, 0 to disable)
229234 -include-running Emit running status updates in addition to terminal (default: terminal only)
230235 -human Human-readable output instead of JSONL (for terminal, not piping)
231236 -log-level <level> Log level: debug, info, warn, error (default: info)`)
......@@ -892,10 +897,17 @@ func runMonitor(cfg *Cfg) error {
892897 ticker := time.NewTicker(cfg.MonitorInterval)
893898 defer ticker.Stop()
894899
900+ // Optional GC ticker — runs garbage collection on a separate interval.
901+ var gcTicker *time.Ticker
902+ if cfg.GCInterval > 0 {
903+ gcTicker = time.NewTicker(cfg.GCInterval)
904+ defer gcTicker.Stop()
905+ }
906+
895907 // Track per-job display state across ticks (for human output)
896908 jobStates := make(map[string]*monitorJobState) // key: "name/jobID"
897909
898- log.Debug("monitor started", "interval", cfg.MonitorInterval, "artifact_dir", cfg.ArtifactDir)
910+ log.Debug("monitor started", "interval", cfg.MonitorInterval, "gc_interval", cfg.GCInterval, "artifact_dir", cfg.ArtifactDir)
899911 log.Debug("monitoring ci.* sessions for job status, writing status to stdout")
900912
901913 for {
......@@ -904,10 +916,14 @@ func runMonitor(cfg *Cfg) error {
904916 log.Debug("context cancelled, stopping monitor")
905917 return cfg.Ctx.Err()
906918 case <-ticker.C:
907- }
908-
909- if err := monitorTick(cfg, log, output, jobStates); err != nil {
910- log.Error("monitor tick", "err", err)
919+ if err := monitorTick(cfg, log, output, jobStates); err != nil {
920+ log.Error("monitor tick", "err", err)
921+ }
922+ case <-gcTicker.C:
923+ log.Debug("running periodic garbage collection")
924+ if err := runGC(cfg); err != nil {
925+ log.Error("periodic gc", "err", err)
926+ }
911927 }
912928 }
913929 }
+1, -0
......@@ -17,6 +17,7 @@
1717 <span>ID: {{.JobID}}</span>
1818 <span>Duration: {{.Duration}}</span>
1919 {{if .ExitCode}}<span>Exit: {{.ExitCode}}</span>{{end}}
20+ <span>Connect: <code>zmx attach {{.SessionName}}</code></span>
2021 </div>
2122 <div class="zmx-output">{{.Content}}</div>
2223 <div class="links">