API workers share startup and OAuth sign-ins through the data folder

This commit is contained in:
Roberto Treviño
2026-11-29 01:32:08 -06:00
parent 4212c4d0b5
commit ae4638e4dd
3 changed files with 53 additions and 12 deletions
+12 -1
View File
@@ -154,5 +154,16 @@ async def first_admin() -> None:
@asynccontextmanager
async def lifespan(_app: FastAPI) -> AsyncIterator[None]:
await first_admin()
"""Each API worker starts here; one at a time (a lock in the data folder), so the
users table, the first administrator and the session secret are made once."""
import fcntl
DATA_DIR.mkdir(parents=True, exist_ok=True)
with open(DATA_DIR / "startup.lock", "w") as lock:
fcntl.flock(lock, fcntl.LOCK_EX)
try:
_secret()
await first_admin()
finally:
fcntl.flock(lock, fcntl.LOCK_UN)
yield