Phase 13, part 5: each team's jobs, locks, files and sign-ins
Background jobs run for each active team on its own Server and under its own locks, a few teams at a time and from a different team each round, so the work is shared between copies of the app and no team holds up another. Each team's files are under its own prefix, and an OAuth sign-in comes back only to the team that started it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+19
-14
@@ -258,23 +258,12 @@ func (s *Server) syncSearchConsole(ctx context.Context) error {
|
||||
// RunSEO syncs Search Console twice a day.
|
||||
func (s *Server) RunSEO(ctx context.Context) {
|
||||
if s.alone() { // otherwise "running" may be another copy's work
|
||||
if err := seo.RecoverAudits(s.DB); err != nil {
|
||||
s.Log.Error("seo: recovering audits", "err", err)
|
||||
}
|
||||
if err := seo.RecoverChanges(s.DB); err != nil {
|
||||
s.Log.Error("seo: recovering changes", "err", err)
|
||||
}
|
||||
if err := seo.RecoverBriefs(s.DB); err != nil {
|
||||
s.Log.Error("seo: recovering briefs", "err", err)
|
||||
}
|
||||
if err := sites.RecoverPages(s.DB); err != nil {
|
||||
s.Log.Error("sites: recovering pages", "err", err)
|
||||
}
|
||||
s.eachTeam(ctx, func(_ context.Context, s *Server) { s.recoverSEO() })
|
||||
}
|
||||
tick := time.NewTicker(30 * time.Minute)
|
||||
defer tick.Stop()
|
||||
for {
|
||||
s.jobDo(ctx, "seo", func(ctx context.Context) {
|
||||
s.jobDo(ctx, "seo", func(ctx context.Context, s *Server) {
|
||||
s.weeklyAudits(time.Now())
|
||||
if s.gsc() != nil {
|
||||
due := false
|
||||
@@ -611,7 +600,7 @@ func (s *Server) seoAuditRun(w http.ResponseWriter, r *http.Request) {
|
||||
// site.
|
||||
func (s *Server) startAudit(site seoSite, speed bool) {
|
||||
// One audit per site at a time, across copies of the app.
|
||||
lctx, release, err := s.jobs().TryLock(context.Background(), "audit:"+site.URL)
|
||||
lctx, release, err := s.jobs().TryLock(context.Background(), s.lockName("audit:"+site.URL))
|
||||
if err != nil {
|
||||
if !errors.Is(err, jobs.ErrBusy) {
|
||||
s.Log.Error("seo: starting the audit", "err", err)
|
||||
@@ -711,3 +700,19 @@ func (s *Server) giteaTest(w http.ResponseWriter, r *http.Request) {
|
||||
s.noteCheck("gitea", data)
|
||||
s.fragment(w, r, "sources", "test-result", data)
|
||||
}
|
||||
|
||||
// recoverSEO marks the work left "running" by a stopped app as stopped.
|
||||
func (s *Server) recoverSEO() {
|
||||
if err := seo.RecoverAudits(s.DB); err != nil {
|
||||
s.Log.Error("seo: recovering audits", "err", err)
|
||||
}
|
||||
if err := seo.RecoverChanges(s.DB); err != nil {
|
||||
s.Log.Error("seo: recovering changes", "err", err)
|
||||
}
|
||||
if err := seo.RecoverBriefs(s.DB); err != nil {
|
||||
s.Log.Error("seo: recovering briefs", "err", err)
|
||||
}
|
||||
if err := sites.RecoverPages(s.DB); err != nil {
|
||||
s.Log.Error("sites: recovering pages", "err", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user