"""Docker worker liveness probe: no localhost Web dependency.""" import os import time from pathlib import Path from . import db def healthy(path=None, max_age=None): file=Path(path) if path is not None else db.DATA/'worker-heartbeat' limit=float(max_age if max_age is not None else os.getenv('SITEFORGE_WORKER_HEALTH_MAX_AGE','45')) if limit <= 0:return False try: age=time.time()-file.stat().st_mtime return -5 <= age < limit except OSError: return False if __name__=='__main__': raise SystemExit(0 if healthy() else 1)