Files
keyhunter-parser/validator_loop.py

41 lines
1.1 KiB
Python

"""Eternal validator loop: every 15 min, validate accumulated NEW keys.
Reuses validate_backlog.run() (importlib of eternal_v10, 40 threads).
Skips round when NEW==0."""
import importlib.util
import sqlite3
import time
from pathlib import Path
PROJ = Path(__file__).resolve().parent
DB = PROJ / "data" / "keys.db"
INTERVAL = 900
import validate_backlog as vb
def new_count():
db = sqlite3.connect(str(DB), timeout=120)
try:
return db.execute("SELECT count(*) FROM keys WHERE status='NEW'").fetchone()[0]
finally:
db.close()
def main():
print(time.strftime("[%H:%M:%S]") + " eternal validator loop start (15 min)", flush=True)
while True:
try:
n = new_count()
if n == 0:
print(time.strftime("[%H:%M:%S]") + " no NEW, skip", flush=True)
else:
print(time.strftime("[%H:%M:%S]") + f" validating {n} NEW", flush=True)
vb.run()
except Exception as e:
print(time.strftime("[%H:%M:%S]") + f" ERR {e}", flush=True)
time.sleep(INTERVAL)
if __name__ == "__main__":
main()