26 lines
894 B
Python
26 lines
894 B
Python
|
|
"""Infrastructure readiness distinct from lightweight process liveness.
|
||
|
|
|
||
|
|
Do not expose DB DSNs, Redis endpoints or filesystem paths in the public response.
|
||
|
|
Redis wake-ups are optional and are not a readiness requirement.
|
||
|
|
"""
|
||
|
|
from pathlib import Path
|
||
|
|
import tempfile
|
||
|
|
from . import db
|
||
|
|
|
||
|
|
|
||
|
|
def readiness() -> bool:
|
||
|
|
try:
|
||
|
|
# SELECT 1 works on SQLite and PostgreSQL and checks actual connectivity.
|
||
|
|
with db.connect() as conn:
|
||
|
|
if conn.execute('SELECT 1 AS ready').fetchone()[0] != 1:
|
||
|
|
return False
|
||
|
|
data=Path(db.DATA)
|
||
|
|
data.mkdir(parents=True,exist_ok=True)
|
||
|
|
# Build artifacts and job results require writable shared storage.
|
||
|
|
with tempfile.NamedTemporaryFile(dir=data, prefix='.ready-', delete=True) as probe:
|
||
|
|
probe.write(b'1')
|
||
|
|
probe.flush()
|
||
|
|
return True
|
||
|
|
except Exception:
|
||
|
|
return False
|