From 0d2fd50f7dea5bdd85ee6660d819ce68568d5870 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Wed, 26 Jul 2023 16:51:06 +0200 Subject: [PATCH] Continued: - command fetch_relays() should be locked - fixed exception when row[column] is NoneType --- fba/commands.py | 3 +++ fba/models/instances.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/fba/commands.py b/fba/commands.py index cd7deb9..b8866b5 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -1864,6 +1864,9 @@ def fetch_instances_social(args: argparse.Namespace) -> int: def fetch_relays(args: argparse.Namespace) -> int: logger.debug("args[]='%s' - CALLED!", type(args)) + logger.debug("Invoking locking.acquire() ...") + locking.acquire() + if args.domain is not None and args.domain != "": database.cursor.execute("SELECT domain, software FROM instances WHERE software IN ('activityrelay', 'aoderelay', 'selective-relay') AND domain = ? LIMIT 1", [args.domain]) else: diff --git a/fba/models/instances.py b/fba/models/instances.py index 69b6f15..2f6f826 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -315,7 +315,10 @@ def is_recent(domain: str, column: str = "last_instance_fetch") -> bool: database.cursor.execute(f"SELECT {column} FROM instances WHERE domain = ? LIMIT 1", [domain]) # Fetch row - fetched = float(database.cursor.fetchone()[column]) + row = database.cursor.fetchone() + + fetched = float(row[column]) if row[column] is not None else 0.0 + diff = (time.time() - fetched) logger.debug("fetched[%s]='%s',key='%s',diff=%f", type(fetched), fetched, key, diff) -- 2.39.5