e871b05b38
CI / Test (linux/amd64) (pull_request) Successful in 34s
CI / Lint (pull_request) Failing after 16s
CI / Build (windows/amd64) (pull_request) Successful in 22s
CI / Build (linux/amd64) (pull_request) Successful in 20s
CI / Build (linux/arm64) (pull_request) Successful in 21s
Cleanup pass over the repo so CI can enforce lint going forward
without the only-new-issues escape hatch:
* gofumpt -w across the tree (31 hits, all formatting)
* misspell --fix (25 hits, US-locale spelling) — but reverted on
api.JobCancelled = "cancelled" since that literal is the wire +
DB CHECK constraint value, plus matched the case in store/fleet.go
back to "cancelled" and added //nolint:misspell on both for the
next time someone reaches for the auto-fix
* Wrap every `defer rows.Close()` / `defer stmt.Close()` /
`defer res.Body.Close()` in `defer func() { _ = .Close() }()`
to satisfy errcheck without losing the close itself
* websocket.Dial callers (1 prod, 4 tests) now capture + close the
upgrade response Body — coder/websocket can return res with a nil
Body on success, so the test deferred-closes guard against that
* Annotate the two genuine-by-design nilerr cases with //nolint
comments explaining why nil-on-error is the contract (cookie
missing = no session; ctx cancelled mid-backoff = clean shutdown)
* Add brief godoc on the 10 exported const groups + types that
revive flagged (api.HostOS/HostArch/JobKind/JobStatus/LogStream/
ErrorCode, restic.EventKind, store.Role, web.FS)
* Drop the unused (*Server).userByID method
* Inline the unparam baseView(active) — every UI page is under
the dashboard primary nav today
Result: `golangci-lint run ./...` reports 0 issues. CI lint job
no longer needs only-new-issues: true; X-06 follow-up entry in
tasks.md removed.
75 lines
2.5 KiB
Go
75 lines
2.5 KiB
Go
package store
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
"fmt"
|
|
)
|
|
|
|
// CreateDefaultRepoMaintenance inserts the default cadences for a
|
|
// host. Called once at host enrolment alongside CreateHost. Safe to
|
|
// re-call (uses INSERT OR IGNORE so a manual repair doesn't blow up
|
|
// an already-seeded host).
|
|
func (st *Store) CreateDefaultRepoMaintenance(ctx context.Context, hostID string) error {
|
|
_, err := st.db.ExecContext(ctx,
|
|
`INSERT OR IGNORE INTO host_repo_maintenance (host_id) VALUES (?)`,
|
|
hostID)
|
|
if err != nil {
|
|
return fmt.Errorf("store: seed repo maintenance: %w", err)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// GetRepoMaintenance returns the cadence row for a host. Returns
|
|
// ErrNotFound if absent — caller should usually treat that as
|
|
// "needs CreateDefaultRepoMaintenance" rather than a hard error.
|
|
func (st *Store) GetRepoMaintenance(ctx context.Context, hostID string) (*HostRepoMaintenance, error) {
|
|
row := st.db.QueryRowContext(ctx,
|
|
`SELECT host_id, forget_cron, forget_enabled,
|
|
prune_cron, prune_enabled,
|
|
check_cron, check_enabled, check_subset_pct
|
|
FROM host_repo_maintenance WHERE host_id = ?`, hostID)
|
|
var (
|
|
m HostRepoMaintenance
|
|
forgetEnabled, pruneEnabled, checkEnabled int
|
|
)
|
|
err := row.Scan(&m.HostID,
|
|
&m.ForgetCron, &forgetEnabled,
|
|
&m.PruneCron, &pruneEnabled,
|
|
&m.CheckCron, &checkEnabled, &m.CheckSubsetPct)
|
|
if errors.Is(err, sql.ErrNoRows) {
|
|
return nil, ErrNotFound
|
|
}
|
|
if err != nil {
|
|
return nil, fmt.Errorf("store: get repo maintenance: %w", err)
|
|
}
|
|
m.ForgetEnabled = forgetEnabled != 0
|
|
m.PruneEnabled = pruneEnabled != 0
|
|
m.CheckEnabled = checkEnabled != 0
|
|
return &m, nil
|
|
}
|
|
|
|
// UpdateRepoMaintenance replaces every editable field. Doesn't bump
|
|
// the schedule version — these run on the server's own ticker, not
|
|
// the agent's local cron, so the agent doesn't need to know.
|
|
func (st *Store) UpdateRepoMaintenance(ctx context.Context, m *HostRepoMaintenance) error {
|
|
if m.HostID == "" {
|
|
return errors.New("store: repo maintenance host_id required")
|
|
}
|
|
_, err := st.db.ExecContext(ctx,
|
|
`UPDATE host_repo_maintenance SET
|
|
forget_cron = ?, forget_enabled = ?,
|
|
prune_cron = ?, prune_enabled = ?,
|
|
check_cron = ?, check_enabled = ?, check_subset_pct = ?
|
|
WHERE host_id = ?`,
|
|
m.ForgetCron, boolToInt(m.ForgetEnabled),
|
|
m.PruneCron, boolToInt(m.PruneEnabled),
|
|
m.CheckCron, boolToInt(m.CheckEnabled), m.CheckSubsetPct,
|
|
m.HostID)
|
|
if err != nil {
|
|
return fmt.Errorf("store: update repo maintenance: %w", err)
|
|
}
|
|
return nil
|
|
}
|