#!/usr/bin/env python3 # -*- coding: utf-8 -*- """Return exit 0 when the full collection interval is due. The shell scheduler wakes every five minutes. This gate reads the same `full_interval_min` setting as the web config, so changing that single field changes both the full collection and the history-snapshot cadence. A stamp file is updated only after a complete run, so a failed run is retried on the next scheduler tick. """ import os import sys import time HERE = os.path.dirname(os.path.abspath(__file__)) sys.path.insert(0, HERE) import l2cfg # noqa: E402 def main(): try: cfg = l2cfg.config() interval = max(5, int(cfg.get('full_interval_min') or 5)) except Exception as exc: # Never let a temporary config/DB read failure block collection. print('due check config fallback: %s' % exc) interval = 5 stamp = os.environ.get('L2_FULL_STAMP') or '/tmp/l2_full_last' try: last = os.path.getmtime(stamp) except OSError: last = 0 if time.time() - last >= interval * 60: return 0 return 1 if __name__ == '__main__': sys.exit(main())