From 62cfe85f186515b24370268912b00efd67776346 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Fri, 2 Jun 2023 11:55:26 +0200 Subject: [PATCH] Continued: - renamed update_nodeinfos() to update_instance_data() - also only delete pending instance data if UPDATE statement has updated something (at least the timestamps SHOULD cause a row update) --- fba.py | 45 +++++++++++++++++++++++---------------------- fetch_instances.py | 2 +- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/fba.py b/fba.py index 2638800..91efa62 100644 --- a/fba.py +++ b/fba.py @@ -73,7 +73,7 @@ api_headers = { # Found info from node, such as nodeinfo URL, detection mode that needs to be # written to database. Both arrays must be filled at the same time or else -# update_nodeinfos() will fail +# update_instance_data() will fail nodeinfos = { # Detection mode: 'AUTO_DISCOVERY', 'STATIC_CHECKS' or 'GENERATOR' # NULL means all detection methods have failed (maybe still reachable instance) @@ -352,8 +352,8 @@ def update_last_blocked(domain: str): nodeinfos["last_blocked"] = time.time() # Running pending updated - # DEBUG: print(f"DEBUG: Invoking update_nodeinfos({domain}) ...") - update_nodeinfos(domain) + # DEBUG: print(f"DEBUG: Invoking update_instance_data({domain}) ...") + update_instance_data(domain) # DEBUG: print("DEBUG: EXIT!") @@ -372,7 +372,7 @@ def has_pending_nodeinfos(domain: str) -> bool: # DEBUG: print(f"DEBUG: has_pending='{has_pending}' - EXIT!") return has_pending -def update_nodeinfos(domain: str): +def update_instance_data(domain: str): if type(domain) != str: raise ValueError(f"WARNING: domain[]={type(domain)} is not 'str'") @@ -401,22 +401,23 @@ def update_nodeinfos(domain: str): # DEBUG: print(f"DEBUG: Success! (rowcount={cursor.rowcount })") if cursor.rowcount == 0: - print("WARNING: Did not update any rows:", domain) - else: - connection.commit() + print(f"WARNING: Did not update any rows: domain='{domain}',fields()={len(fields)} - EXIT!") + return + + connection.commit() + + # DEBUG: print("DEBUG: Deleting nodeinfos for domain:", domain) + for key in nodeinfos: + try: + # DEBUG: print("DEBUG: Deleting key:", key) + del nodeinfos[key][domain] + except: + pass except BaseException as e: print(f"ERROR: failed SQL query: domain='{domain}',sql='{sql}',exception[{type(e)}]:'{str(e)}'") sys.exit(255) - # DEBUG: print("DEBUG: Deleting nodeinfos for domain:", domain) - for key in nodeinfos: - try: - # DEBUG: print("DEBUG: Deleting key:", key) - del nodeinfos[key][domain] - except: - pass - # DEBUG: print("DEBUG: EXIT!") def log_error(domain: str, res: any): @@ -473,8 +474,8 @@ def update_last_error(domain: str, res: any): nodeinfos["last_error_details"][domain] = res.reason # Running pending updated - # DEBUG: print(f"DEBUG: Invoking update_nodeinfos({domain}) ...") - update_nodeinfos(domain) + # DEBUG: print(f"DEBUG: Invoking update_instance_data({domain}) ...") + update_instance_data(domain) log_error(domain, res) @@ -488,8 +489,8 @@ def update_last_instance_fetch(domain: str): nodeinfos["last_instance_fetch"][domain] = time.time() # Running pending updated - # DEBUG: print(f"DEBUG: Invoking update_nodeinfos({domain}) ...") - update_nodeinfos(domain) + # DEBUG: print(f"DEBUG: Invoking update_instance_data({domain}) ...") + update_instance_data(domain) # DEBUG: print("DEBUG: EXIT!") @@ -502,8 +503,8 @@ def update_last_nodeinfo(domain: str): nodeinfos["last_updated"][domain] = time.time() # Running pending updated - # DEBUG: print(f"DEBUG: Invoking update_nodeinfos({domain}) ...") - update_nodeinfos(domain) + # DEBUG: print(f"DEBUG: Invoking update_instance_data({domain}) ...") + update_instance_data(domain) # DEBUG: print("DEBUG: EXIT!") @@ -1101,7 +1102,7 @@ def add_instance(domain: str, origin: str, originator: str, path: str = None): if has_pending_nodeinfos(domain): # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo being updated ...") - update_nodeinfos(domain) + update_instance_data(domain) remove_pending_error(domain) if domain in pending_errors: diff --git a/fetch_instances.py b/fetch_instances.py index 3ff4918..2311e85 100755 --- a/fetch_instances.py +++ b/fetch_instances.py @@ -38,7 +38,7 @@ def fetch_instances(domain: str, origin: str, software: str, path: str = None): return elif fba.has_pending_nodeinfos(domain): # DEBUG: print(f"DEBUG: domain='{domain}' has pending nodeinfo data, flushing ...") - fba.update_nodeinfos(domain) + fba.update_instance_data(domain) print(f"INFO: Checking {len(peerlist)} instances from {domain} ...") for instance in peerlist: -- 2.39.5