"""Automatic, bounded-memory sweeps; errors never imply that objects are absent.""" import json from pathlib import Path import sys import time import signal import threading sys.path.insert(0,str(Path(__file__).resolve().parents[1])) from app import store, object_store from reconcile import reconcile stop=threading.Event() signal.signal(signal.SIGTERM,lambda *_: stop.set()) signal.signal(signal.SIGINT,lambda *_: stop.set()) store.pool.open(wait=True,timeout=30) try: while not stop.is_set(): try: print(json.dumps(reconcile(object_store,apply=True,grace_seconds=300)),flush=True) except Exception as exc: print(json.dumps({'status':'retry_next_sweep','error_type':type(exc).__name__}),flush=True) stop.wait(60) finally: store.pool.close() object_store.close()