A customer's portal had no Images or 3D pages: nobody had written a
definition for either, on a cluster whose V100 runs both. The leading
control plane now adds flux-schnell and triposr, on demand, once a node
has a card that fits one, the cluster installs ComfyUI, and the catalog
makes nothing of that kind. presets.auto (a live setting, on by default)
turns it off; a preset somebody removes is recorded as declined and not
added back until added again by hand. Each addition is in the audit log.
GET /api/v1/presets says how each preset stands, the ComfyUI the cluster
installs, and why one is not added; POST /api/v1/presets/{name} adds one
(setting engines.comfyui where there is none); PUT /api/v1/presets/auto
switches it.
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
73 lines
2.3 KiB
Go
73 lines
2.3 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// PresetState is one preset as it stands in this cluster.
|
|
type PresetState struct {
|
|
Name string
|
|
// AddedBy is "auto" when the leader added it, who did otherwise.
|
|
AddedBy string
|
|
AddedAt time.Time
|
|
// Declined is somebody removing it after it was added: the leader does
|
|
// not add it back by itself.
|
|
Declined bool
|
|
DeclinedBy string
|
|
DeclinedAt time.Time
|
|
}
|
|
|
|
// PresetAdder is the AddedBy of a preset the leader added by itself.
|
|
const PresetAdder = "auto"
|
|
|
|
// PresetStates is every preset that was ever added or declined, by name.
|
|
func (s *DB) PresetStates(ctx context.Context) (map[string]PresetState, error) {
|
|
rows, err := s.db.QueryContext(ctx,
|
|
`SELECT name, added_by, added_at, declined, declined_by, declined_at FROM preset_state`)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer func() { _ = rows.Close() }()
|
|
out := map[string]PresetState{}
|
|
for rows.Next() {
|
|
var p PresetState
|
|
var added, declinedAt int64
|
|
var declined int
|
|
if err := rows.Scan(&p.Name, &p.AddedBy, &added, &declined, &p.DeclinedBy, &declinedAt); err != nil {
|
|
return nil, err
|
|
}
|
|
p.AddedAt, p.Declined, p.DeclinedAt = presetTime(added), declined != 0, presetTime(declinedAt)
|
|
out[p.Name] = p
|
|
}
|
|
return out, rows.Err()
|
|
}
|
|
|
|
// PresetAdded records a preset added, by whom, and clears its decline.
|
|
func (s *DB) PresetAdded(ctx context.Context, name, by string, at time.Time) error {
|
|
_, err := s.db.ExecContext(ctx,
|
|
`INSERT INTO preset_state (name, added_by, added_at, declined, declined_by, declined_at) VALUES (?, ?, ?, 0, '', 0)
|
|
ON CONFLICT (name) DO UPDATE SET added_by = excluded.added_by, added_at = excluded.added_at,
|
|
declined = 0, declined_by = '', declined_at = 0`,
|
|
name, by, at.UnixMilli())
|
|
return err
|
|
}
|
|
|
|
// PresetDeclined records a preset removed after it was added, so the leader
|
|
// does not add it back.
|
|
func (s *DB) PresetDeclined(ctx context.Context, name, by string, at time.Time) error {
|
|
_, err := s.db.ExecContext(ctx,
|
|
`INSERT INTO preset_state (name, declined, declined_by, declined_at) VALUES (?, 1, ?, ?)
|
|
ON CONFLICT (name) DO UPDATE SET declined = 1, declined_by = excluded.declined_by, declined_at = excluded.declined_at`,
|
|
name, by, at.UnixMilli())
|
|
return err
|
|
}
|
|
|
|
// presetTime is a stored instant, zero for none.
|
|
func presetTime(ms int64) time.Time {
|
|
if ms == 0 {
|
|
return time.Time{}
|
|
}
|
|
return fromMillis(ms)
|
|
}
|