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>
This commit is contained in:
2026-11-25 07:56:47 -07:00
co-authored by Claude Opus 5.5
parent ba6114f367
commit c6c4c40600
18 changed files with 873 additions and 150 deletions
+16
View File
@@ -13,4 +13,20 @@
<p class="help">Supermarket also comes as a <strong>server</strong> edition, for a team signing in on a server, and a <strong>multi-tenant</strong> one, for many teams at one address. The edition is chosen with <code>SUPERMARKET_MODE</code> when it starts; <code>supermarket config</code> checks the settings.</p>
{{end}}
</section>
<section class="card">
<h2>Running</h2>
<p class="help">Copies of Supermarket using this database, and the work each has under way. Only one copy does a background job at a time; if one stops, another takes its work over within two minutes.</p>
<table class="list">
<thead><tr><th>Copy</th><th>Host</th><th>Version</th><th>Started</th><th>Last seen</th></tr></thead>
<tbody>
{{range .Copies}}<tr><td><code>{{.ID}}</code>{{if .This}} <span class="muted">(this one)</span>{{end}}</td><td>{{.Host}}</td><td>{{.Version}}</td><td>{{ago .Started}}</td><td>{{ago .Seen}}</td></tr>
{{end}}
</tbody>
</table>
{{if .Locks}}
<h3>Under way</h3>
<ul>{{range .Locks}}<li><code>{{.Name}}</code> on <code>{{.Instance}}</code>, since {{ago .Since}}</li>{{end}}</ul>
{{else}}<p class="muted">No background work under way just now.</p>{{end}}
</section>
{{end}}{{template "settings-end"}}{{end}}