oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1package runner
2
3import (
4 "context"
5 "encoding/json"
6 "errors"
7
8 "amadan.net/oficina/equipo/internal/runnerproto"
9)
10
11type ProcessIdentity = runnerproto.ProcessIdentity
12type ProcessOwner = runnerproto.ProcessOwner
13type ProcessInventory = runnerproto.ProcessInventory
14type ContainmentProof = runnerproto.ContainmentProof
15
16// Persistent supervisor state shares the journal's FULL synchronous commits.
17func (j *Journal) saveState(ctx context.Context, kind, key string, v any) error {
18 raw, err := json.Marshal(v)
19 if err != nil {
20 return err
21 }
22 if len(raw) > 3<<20 {
23 return ErrJournal
24 }
25 _, 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)
26 if err != nil {
27 if errors.Is(err, context.Canceled) || errors.Is(err, context.DeadlineExceeded) {
28 return err
29 }
30 return j.storageFailure(ctx, err)
31 }
32 return nil
33}
34func (j *Journal) readStates(ctx context.Context, kind string, out any) error {
35 rows, err := j.db.QueryContext(ctx, "SELECT body FROM journal_supervisor WHERE kind=? ORDER BY state_key", kind)
36 if err != nil {
37 return err
38 }
39 defer rows.Close()
40 list := []json.RawMessage{}
41 for rows.Next() {
42 var b []byte
43 if err = rows.Scan(&b); err != nil {
44 return err
45 }
46 list = append(list, b)
47 }
48 if err = rows.Err(); err != nil {
49 return err
50 }
51 raw, err := json.Marshal(list)
52 if err != nil {
53 return err
54 }
55 return json.Unmarshal(raw, out)
56}
57