Files
davidandClaude Opus 5.5 c6c4c40600 Phase 9, part 6: background work shared safely between copies of the app
internal/jobs keeps named locks as leases in the database (schema 31:
locks, instances), taken with one conditional UPDATE on SQLite or Postgres,
renewed while the work runs and lapsing if its copy stops. Each background
loop's turn, sending an email, audits, discovery runs and imports run
under a lock; OAuth sign-ins under way are kept in the database. Copies
check in, and work marked running is recovered at start only when no
other copy is alive. Settings -> About lists the copies and work under
way.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 07:56:47 -07:00

50 lines
1.2 KiB
Go

package web
import (
"net/http"
"os"
"supermarket/internal/config"
"supermarket/internal/db"
"supermarket/internal/jobs"
)
// config is how this Supermarket is run: the local edition's defaults when
// none was given (tests).
func (s *Server) config() *config.Config {
if s.Config != nil {
return s.Config
}
c, _ := config.Load(func(k string) string {
switch k {
case config.EnvData, config.EnvHostData:
return s.DataDir
case config.EnvPublicURL:
return s.PublicURL
case config.EnvMode:
return ""
}
return os.Getenv(k)
})
return c
}
type aboutData struct {
Edition config.Edition
Version string
Schema int
Items []config.Item
Copies []jobs.Instance // copies of the app running now
Locks []jobs.Held // work they have under way
}
// aboutPage shows the edition and how it's run (Settings → About).
func (s *Server) aboutPage(w http.ResponseWriter, r *http.Request) {
c := s.config()
d := aboutData{Edition: c.Edition, Version: s.Version, Schema: db.Schema(), Items: c.Summary()}
d.Copies, _ = s.jobs().Instances()
d.Locks, _ = s.jobs().Locks()
s.render(w, r, "about", page{Title: "About", Nav: "settings/about", Data: d})
}