A1: Django skeleton with web and worker processes (ADR-54, ADR-55, WEB-01, WEB-07, ARC-70..74)

Django 5.2 project (config/, apps/accounts with a custom User and
case-insensitive usernames, apps/lottery with the run_worker command,
apps/web with a placeholder home and /health/live, apps/ops), SQLite in WAL
with IMMEDIATE transactions, secrets and hosts from the environment. The
compose stack is now web + worker + caddy and serves https://localhost; the
old FastAPI service is out of the stack until roadmap D1. The three old
infrastructure tests follow the new Dockerfile and compose.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
davideandClaude Sonnet 5.5 committed 2026-11-16 12:00:57 +01:00
1 parent 79f7ebe53e
commit fc23a75c9b
43 files changed
+709 -61

No files matched your search

+30
View File
@@ -960,3 +960,33 @@ italiano.
*Codice:* `app/rounds/events.py:RoundEventBroadcaster` ·
`app/tx/locks.py:UserLocks` · `app/auth/rate_limit.py:AuthRateLimiters` ·
`app/main.py:lifespan`
## Sito Django (migrazione in corso)
Il nuovo sito sostituisce il backend FastAPI descritto sopra (roadmap A1–D1); finché il vecchio codice
non è rimosso le sezioni precedenti descrivono lo stato storico. Scelte: [ADR-54](adr/ADR-54-django-unico-framework-web-tre-aree.md),
[ADR-55](adr/ADR-55-sqlite-wal-web-worker-processi-separati.md).
- **[ARC-70]** **Database condiviso da due processi.** Il web e il worker usano lo stesso file SQLite in
modalità WAL, con `synchronous=FULL`, chiavi esterne attive e ogni transazione di scrittura aperta con
`BEGIN IMMEDIATE` (`transaction_mode`); un blocco non ottenuto entro 20 secondi è un errore, mai un'attesa
senza fine.
*Stato:* implementato (A1) ·
*Codice:* `config/settings.py:DATABASES` · *Test:* `tests/django/test_scaffold.py::test_sqlite_pragmas_apply_to_a_file_database`
- **[ARC-71]** **Il worker è un processo a sé.** `manage.py run_worker` esegue i compiti di fondo a intervalli
regolari, si ferma in modo pulito su SIGTERM/SIGINT e, nel compose, parte solo dopo che il web è sano (cioè dopo
le migrazioni). Un riavvio del web non ferma il worker e viceversa.
*Stato:* implementato come guscio (A1); i compiti arrivano con A4 e la Fase B ·
*Codice:* `apps/lottery/management/commands/run_worker.py` · *Test:* `tests/django/test_scaffold.py::test_worker_runs_one_tick_and_exits`
- **[ARC-72]** **Nessuna coordinazione in memoria fra web e worker.** Esclusione reciproca e unicità si
ottengono con vincoli e transazioni del database, mai con blocchi o code in memoria.
*Stato:* da implementare (A2 per i vincoli, B6 per la prenotazione degli UTXO).
- **[ARC-73]** **Liveness.** `GET /health/live` risponde `200 {"status": "ok"}` se il processo risponde e il
database si apre, `503` altrimenti; il compose lo usa come healthcheck del servizio `web`.
*Stato:* implementato (A1) ·
*Codice:* `apps/web/views.py:health_live` · *Test:* `tests/django/test_scaffold.py::test_health_live_checks_the_database`
- **[ARC-74]** **Segreto obbligatorio.** Il processo rifiuta di partire se `DJANGO_SECRET_KEY` ha meno di 50
caratteri (come [ADR-11](adr/ADR-11-server-rifiuta-partire-segreti-inadeguati.md) per il vecchio server);
solo `DJANGO_DEBUG=true` (sviluppo senza Docker) ne genera uno non sicuro.
*Stato:* implementato (A1) ·
*Codice:* `config/settings.py` · *Test:* `tests/django/test_scaffold.py::test_refuses_to_start_without_a_secret`