]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Mon, 22 May 2023 09:23:57 +0000 (11:23 +0200)
committerRoland Häder <roland@mxchange.org>
Mon, 22 May 2023 09:41:10 +0000 (11:41 +0200)
- log entire exception message
- show number of errorous instances

api.py
fba.py
index.html

diff --git a/api.py b/api.py
index c0fc29d421be4d079a2ff17badcd9a131a3be8a4..897c2691b33cdaef980837f58b74e7d48ca8e297 100644 (file)
--- 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 dcdcea4d655bfb68ca5cb1d312dce2d31459b7a6..67638c375b7195ddbbe62023de0daf301cc97663 100644 (file)
--- 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]
 
index bcc8bb153c4900027fcc4d30204dc59d71d8e0a6..4ba34131d8e6793706a2c79bac551b69e1dfe767 100644 (file)
             known instances: {{info.known_instances}}<br/>
             indexed instances: {{info.indexed_instances}}<br/>
             blocks recorded: {{info.blocks_recorded}}<br/>
+            errorous instances: {{info.errorous_instances}}<br/>
             source code: <a href="https://git.mxchange.org/?p=fba.git;a=summary" rel="source" target="_blank">git.mxchange.org</a><br /><br />
             {{info.slogan}}
         </div>