From: Roland Häder Date: Sun, 28 May 2023 16:02:05 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=89a7623255dc479d1599c85f0b8a4c77aabb32bc;p=fba.git Continued: - added last_instance_fetch timestamp --- diff --git a/blocks_empty.db b/blocks_empty.db index b83a456..905adbe 100644 Binary files a/blocks_empty.db and b/blocks_empty.db differ diff --git a/fba.py b/fba.py index 95d692b..f54789c 100644 --- a/fba.py +++ b/fba.py @@ -328,6 +328,25 @@ def update_last_error(domain: str, res: any): # DEBUG: print("DEBUG: EXIT!") +def update_last_instance_fetch(domain: str): + #print("DEBUG: Updating last_instance_fetch for domain:", domain) + try: + cursor.execute("UPDATE instances SET last_instance_fetch = ?, last_updated = ? WHERE domain = ? LIMIT 1", [ + time.time(), + time.time(), + domain + ]) + + if cursor.rowcount == 0: + print("WARNING: Did not update any rows:", domain) + + except BaseException as e: + print(f"ERROR: failed SQL query: domain='{domain}',exception:'{str(e)}'") + sys.exit(255) + + connection.commit() + #print("DEBUG: EXIT!") + def update_last_nodeinfo(domain: str): # DEBUG: print("DEBUG: Updating last_nodeinfo for domain:", domain) try: @@ -399,6 +418,8 @@ def get_peers(domain: str, software: str) -> list: # DEBUG: print(f"DEBUG: Adding peer: '{row['host']}'") peers.append(row["host"]) + update_last_instance_fetch(domain) + # DEBUG: print("DEBUG: Returning peers[]:", type(peers)) return peers elif software == "lemmy": @@ -423,7 +444,7 @@ def get_peers(domain: str, software: str) -> list: except BaseException as e: print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception:'{str(e)}'") - update_last_nodeinfo(domain) + update_last_instance_fetch(domain) # DEBUG: print("DEBUG: Returning peers[]:", type(peers)) return peers @@ -462,7 +483,7 @@ def get_peers(domain: str, software: str) -> list: except BaseException as e: print(f"WARNING: Exception during fetching JSON: domain='{domain}',exception:'{str(e)}'") - update_last_nodeinfo(domain) + update_last_instance_fetch(domain) # DEBUG: print("DEBUG: Returning peers[]:", type(peers)) return peers @@ -498,7 +519,7 @@ def get_peers(domain: str, software: str) -> list: print("WARNING: Some error during get():", domain, e) update_last_error(domain, e) - update_last_nodeinfo(domain) + update_last_instance_fetch(domain) # DEBUG: print("DEBUG: Returning peers[]:", type(peers)) return peers diff --git a/fetch_instances.py b/fetch_instances.py index ceadd47..c5188fd 100644 --- a/fetch_instances.py +++ b/fetch_instances.py @@ -53,7 +53,7 @@ fetch_instances(instance, None, None) # Loop through some instances fba.cursor.execute( - "SELECT domain,origin,software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe', 'lemmy') AND (last_nodeinfo IS NULL OR last_nodeinfo < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]] + "SELECT domain,origin,software FROM instances WHERE software IN ('pleroma', 'mastodon', 'friendica', 'misskey', 'gotosocial', 'bookwyrm', 'takahe', 'lemmy') AND (last_instance_fetch IS NULL OR last_instance_fetch < ?) ORDER BY rowid DESC", [time.time() - fba.config["recheck_instance"]] ) rows = fba.cursor.fetchall()