From a5c2b67e829b592c5810715dc777605f5658051e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 2 Jul 2023 20:16:01 +0200 Subject: [PATCH] Continued: - command update_nodeinfo() now supports --domain and --software parameter - without them only out-dated instances are being check - also determined software is being updated --- fba/boot.py | 2 ++ fba/commands.py | 25 ++++++++++++++++++++++--- fba/models/instances.py | 15 +++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/fba/boot.py b/fba/boot.py index d04fd95..c25f707 100644 --- a/fba/boot.py +++ b/fba/boot.py @@ -188,6 +188,8 @@ def init_parser(): help="Updates nodeinfo for all instances", ) parser.set_defaults(command=commands.update_nodeinfo) + parser.add_argument("--domain", help="Instance name (aka. domain)") + parser.add_argument("--software", help="Name of software, e.g. 'lemmy'") logger.debug("EXIT!") diff --git a/fba/commands.py b/fba/commands.py index cf88126..5a59379 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -1374,15 +1374,34 @@ def fetch_fedilist(args: argparse.Namespace) -> int: def update_nodeinfo(args: argparse.Namespace) -> int: logger.debug("args[]='%s' - CALLED!", type(args)) - database.cursor.execute("SELECT domain FROM instances WHERE last_nodeinfo < ?", [time.time() - config.get("recheck_block")]) + if args.domain is not None and args.domain != "": + logger.debug("Fetching args.domain='%s'", args.domain) + database.cursor.execute("SELECT domain FROM instances WHERE domain = ?", [args.domain]) + elif args.software is not None and args.software != "": + logger.info("Fetching domains for args.software='%s'", args.software) + database.cursor.execute("SELECT domain FROM instances WHERE software = ?", [args.software]) + else: + logger.info("Fetching domains for recently updated ...") + database.cursor.execute("SELECT domain FROM instances WHERE last_nodeinfo < ? OR last_nodeinfo IS NULL", [time.time() - config.get("recheck_block")]) domains = database.cursor.fetchall() logger.info("Checking %d domain(s) ...", len(domains)) for row in domains: - logger.info("Updating nodeinfo for row[domain]='%s' ...", row["domain"]) - federation.fetch_nodeinfo(row["domain"]) + logger.debug("row[]='%s'", type(row)) + try: + logger.info("Updating nodeinfo for row[domain]='%s' ...", row["domain"]) + software = federation.determine_software(row["domain"]) + + logger.info("Determined software='%s'", software) + instances.set_software(row["domain"], software) + instances.set_success(row["domain"]) + except network.exceptions as exception: + logger.warning("Exception '%s' during updating nodeinfo for row[domain]='%s'", type(exception), row["domain"]) + instances.set_last_error(row["domain"], exception) + instances.set_last_nodeinfo(row["domain"]) + instances.update_data(row["domain"]) logger.debug("Success! - EXIT!") return 0 diff --git a/fba/models/instances.py b/fba/models/instances.py index 59dc6b2..2017153 100644 --- a/fba/models/instances.py +++ b/fba/models/instances.py @@ -65,6 +65,8 @@ _pending = { "last_error_details" : {}, # Wether obfuscation has been used "has_obfuscation" : {}, + # Determined software + "software" : {}, } def _set_data(key: str, domain: str, value: any): @@ -445,3 +447,16 @@ def set_has_obfuscation(domain: str, status: bool): # Set timestamp _set_data("has_obfuscation", domain, status) logger.debug("EXIT!") + +def set_software(domain: str, software: str): + logger.debug("domain='%s',software='%s' - CALLED!", domain, software) + domain_helper.raise_on(domain) + + if not isinstance(software, str) and software is not None: + raise ValueError(f"Parameter software[]='{type(software)}' is not 'str'") + elif software == "": + raise ValueError("Parameter 'software' is empty") + + # Set timestamp + _set_data("software", domain, software) + logger.debug("EXIT!") -- 2.39.5