mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
refactor(db): port sleep/wake sweeper to sqlc
Tranche 7 — all 11 raw sites in sleeper.go. Adds sleep_enabled and sleep_idle_minutes to schema.sql and three runtime.sql queries: ListSleepCandidates, GetServiceDomainText, GetServiceStatusText. Status writes reuse SetServiceStatus; the wake loader reuses GetServiceRuntimeWithOwner (the projects join is FK-safe). Also drops a dead port read in handleServiceSleep that was loaded but never used. TestRuntimeLiveInvariants now covers the sweep filter and both text lookups on live Postgres. Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
269e031761
commit
23d085c98f
7 files changed
+173
-91
No files matched your search
@@ -573,4 +573,29 @@ func TestRuntimeLiveInvariants(t *testing.T) {
|
||||
if row.Replicas != 3 {
|
||||
t.Fatalf("replicas: %+v", row)
|
||||
}
|
||||
|
||||
// Sleeper reads: candidate sweep + domain/status text lookups.
|
||||
_, err = db.Exec(`UPDATE services SET sleep_enabled = true, domain = 'rt.example.com', status = 'running' WHERE id = $1`, serviceID)
|
||||
must(err)
|
||||
cands, err := q.ListSleepCandidates(ctx)
|
||||
if err != nil {
|
||||
t.Fatalf("sleep candidates: %v", err)
|
||||
}
|
||||
var mine *sqlcdb.ListSleepCandidatesRow
|
||||
for i := range cands {
|
||||
if cands[i].ID == serviceID {
|
||||
mine = &cands[i]
|
||||
}
|
||||
}
|
||||
if mine == nil || mine.SleepIdleMinutes != 15 {
|
||||
t.Fatalf("candidate missing/idle wrong: %+v", mine)
|
||||
}
|
||||
dom, err := q.GetServiceDomainText(ctx, serviceID)
|
||||
if err != nil || dom != "rt.example.com" {
|
||||
t.Fatalf("domain text: %v %q", err, dom)
|
||||
}
|
||||
st, err := q.GetServiceStatusText(ctx, serviceID)
|
||||
if err != nil || st != "running" {
|
||||
t.Fatalf("status text: %v %q", err, st)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user