package runner import ( "context" "encoding/json" "errors" "amadan.net/oficina/equipo/internal/runnerproto" ) type ProcessIdentity = runnerproto.ProcessIdentity type ProcessOwner = runnerproto.ProcessOwner type ProcessInventory = runnerproto.ProcessInventory type ContainmentProof = runnerproto.ContainmentProof // Persistent supervisor state shares the journal's FULL synchronous commits. func (j *Journal) saveState(ctx context.Context, kind, key string, v any) error { raw, err := json.Marshal(v) if err != nil { return err } if len(raw) > 3<<20 { return ErrJournal } _, err = j.db.ExecContext(ctx, "INSERT INTO journal_supervisor(kind,state_key,body) VALUES(?,?,?) ON CONFLICT(kind,state_key) DO UPDATE SET body=excluded.body", kind, key, raw) if err != nil { if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) { return err } return j.storageFailure(ctx, err) } return nil } func (j *Journal) readStates(ctx context.Context, kind string, out any) error { rows, err := j.db.QueryContext(ctx, "SELECT body FROM journal_supervisor WHERE kind=? ORDER BY state_key", kind) if err != nil { return err } defer rows.Close() list := []json.RawMessage{} for rows.Next() { var b []byte if err = rows.Scan(&b); err != nil { return err } list = append(list, b) } if err = rows.Err(); err != nil { return err } raw, err := json.Marshal(list) if err != nil { return err } return json.Unmarshal(raw, out) }