From: Roland Häder Date: Mon, 22 May 2023 09:23:57 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e46c264b9abb1a89a84c9d89fade8465fadf7668;p=fba.git Continued: - log entire exception message - show number of errorous instances --- diff --git a/api.py b/api.py index c0fc29d..897c269 100644 --- a/api.py +++ b/api.py @@ -14,14 +14,15 @@ templates = Jinja2Templates(directory=".") @app.get(fba.config["base_url"] + "/info") def info(): - fba.cursor.execute("SELECT (SELECT COUNT(domain) FROM instances), (SELECT COUNT(domain) FROM instances WHERE software IN ('pleroma', 'mastodon', 'misskey', 'gotosocial', 'friendica', 'bookwyrm', 'takahe')), (SELECT COUNT(blocker) FROM blocks)") - known, indexed, blocks = fba.cursor.fetchone() + fba.cursor.execute("SELECT (SELECT COUNT(domain) FROM instances), (SELECT COUNT(domain) FROM instances WHERE software IN ('pleroma', 'mastodon', 'misskey', 'gotosocial', 'friendica', 'bookwyrm', 'takahe')), (SELECT COUNT(blocker) FROM blocks), (SELECT COUNT(domain) FROM instances WHERE last_status_code IS NOT NULL)") + known, indexed, blocks, errorous = fba.cursor.fetchone() return { - "known_instances" : known, - "indexed_instances": indexed, - "blocks_recorded" : blocks, - "slogan" : fba.config["slogan"] + "known_instances" : known, + "indexed_instances" : indexed, + "blocks_recorded" : blocks, + "errorous_instances": errorous, + "slogan" : fba.config["slogan"] } @app.get(fba.config["base_url"] + "/top") diff --git a/fba.py b/fba.py index dcdcea4..67638c3 100644 --- a/fba.py +++ b/fba.py @@ -67,6 +67,10 @@ def update_last_blocked(domain: str): def update_last_error(domain: str, res: any): # NOISY-DEBUG: print("DEBUG: domain,res.status_code:", domain, res.status_code, res.reason) try: + # NOISY-DEBUG: print("DEBUG: res[]:", type(res)) + if isinstance(res, BaseException): + res = str(res) + if type(res) is str: cursor.execute("UPDATE instances SET last_status_code = 999, last_error_details = ?, last_updated = ? WHERE domain = ?", [ res, @@ -183,14 +187,14 @@ def fetch_nodeinfo(domain: str) -> list: update_last_error(domain, res) continue - except: + except BaseException as e: # NOISY-DEBUG: print("DEBUG: Cannot fetch API request:", request) + update_last_error(domain, e) pass # NOISY-DEBUG: print("DEBUG: json[]:", type(json)) if json is None or len(json) == 0: print("WARNING: Failed fetching nodeinfo from domain:", domain) - update_last_error(domain, "Cannot fetch nodeinfo") # NOISY-DEBUG: print("DEBUG: Returning json[]:", type(json)) return json @@ -222,9 +226,9 @@ def fetch_wellknown_nodeinfo(domain: str) -> list: else: print("WARNING: nodeinfo does not contain 'links':", domain) - except: + except BaseException as e: print("WARNING: Failed fetching .well-known info:", domain) - update_last_error(domain, "Cannot fetch .well-known") + update_last_error(domain, e) pass # NOISY-DEBUG: print("DEBUG: Returning json[]:", type(json)) @@ -378,7 +382,7 @@ def add_instance(domain: str, origin: str, originator: str): ) if domain in pending_errors: - print("DEBUG: domain has pending error be updated:", domain) + # NOISY-DEBUG: print("DEBUG: domain has pending error be updated:", domain) update_last_error(domain, pending_errors[domain]) del pending_errors[domain] diff --git a/index.html b/index.html index bcc8bb1..4ba3413 100644 --- a/index.html +++ b/index.html @@ -171,6 +171,7 @@ known instances: {{info.known_instances}}
indexed instances: {{info.indexed_instances}}
blocks recorded: {{info.blocks_recorded}}
+ errorous instances: {{info.errorous_instances}}
source code: git.mxchange.org

{{info.slogan}}