API workers share startup and OAuth sign-ins through the data folder
This commit is contained in:
+12
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user