- Config: remove _ConfigAccessor and ConfigManager; use __getattr__ for lazy loading on single _Config class; re-register self as _instance in __getattr__ so reset() always clears the correct object (item 1) - upload_tracker: replace hand-rolled JSON store with sqlite3; auto-migrates existing JSON on first run; remove dead record_frigate_file function; connection re-opens when CACHE_DIR changes for test isolation (items 2, 8) - diversity: move ThreadPoolExecutor import to module level; inject optional fetch_fn parameter for testability (items 3, 6) - pyproject: consolidate 4 variant files into extras (gpu/rocm/intel/cpu); update Dockerfile to use --extra flag; delete variant pyproject/lock files; uv.lock needs regen with `uv lock` after this change (item 4) - jobs: extract _build_job helper to separate business logic from terminal I/O; auto_configure delegates dedup/selection to _build_job (item 5) - logging: convert f-string log calls to % interpolation throughout all winnow/ modules (item 7) - reconcile: new module with reconcile_frigate_mappings and enrich_asset_with_face_data extracted from executor.py (item 9) - scheduler: print next scheduled run time after startup and after each run; fix f-string logger.error call (item 10)
51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
import logging
|
|
import os
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
try:
|
|
from croniter import croniter
|
|
except ImportError:
|
|
print("croniter not installed. Run: uv add croniter")
|
|
sys.exit(1)
|
|
|
|
# Imported at module level so models loaded during the first run stay
|
|
# resident in memory across all subsequent scheduled runs.
|
|
from winnow.cli import main
|
|
|
|
SCHEDULE = os.environ["CRON_SCHEDULE"]
|
|
INSIGHTFACE_HOME = os.environ.get("INSIGHTFACE_HOME", "/models/.insightface")
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def check_models() -> None:
|
|
buffalo = Path(INSIGHTFACE_HOME) / "models" / "buffalo_l"
|
|
if not buffalo.exists():
|
|
print(" InsightFace Buffalo_L not found — will download on first run", flush=True)
|
|
|
|
|
|
NOW = time.time()
|
|
cron = croniter(SCHEDULE, NOW)
|
|
next_run = cron.get_next(float)
|
|
print(f"Next run: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(next_run))}", flush=True)
|
|
|
|
while True:
|
|
now = time.time()
|
|
if now >= next_run:
|
|
print(f"\n[{time.strftime('%Y-%m-%d %H:%M:%S')}] Starting winnow run...", flush=True)
|
|
check_models()
|
|
try:
|
|
main()
|
|
print("winnow run complete", flush=True)
|
|
except KeyboardInterrupt:
|
|
raise
|
|
except Exception as e:
|
|
logger.error("winnow run failed: %s", e, exc_info=True)
|
|
print(f"winnow run failed: {e}", flush=True)
|
|
next_run = cron.get_next(float)
|
|
print(f"Next run: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(next_run))}", flush=True)
|
|
time.sleep(max(1, next_run - time.time()))
|