from pathlib import Path import fcntl import sys import time sys.path.insert(0, str(Path(__file__).resolve().parents[1])) from attention_digest import DIRECTORY, refresh DIRECTORY.mkdir(parents=True, exist_ok=True, mode=0o700) with (DIRECTORY / 'attention-digest.lock').open('w') as lock: try: fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB) except BlockingIOError: raise SystemExit('Summary worker already running') while True: try: refresh(limit=3) except Exception as error: print('Summary refresh failed: ' + type(error).__name__, flush=True) time.sleep(300)