]> git.mxchange.org Git - fba.git/blobdiff - fba/models/instances.py
Continued:
[fba.git] / fba / models / instances.py
index f27d90e41e9946b4718b335b24324ce838c6eb19..36191bb5b516d76e85b64c8053c485a699d3e1ae 100644 (file)
@@ -41,7 +41,7 @@ logger = logging.getLogger(__name__)
 
 # 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_data() will fail
+# update() will fail
 _pending = {
     # Detection mode
     # NULL means all detection methods have failed (maybe still reachable instance)
@@ -103,7 +103,7 @@ def has_pending(domain: str) -> bool:
     logger.debug("has='%s' - EXIT!", has)
     return has
 
-def update_data(domain: str):
+def update(domain: str):
     logger.debug("domain='%s' - CALLED!", domain)
     domain_helper.raise_on(domain)
     if not has_pending(domain):
@@ -123,7 +123,7 @@ def update_data(domain: str):
 
     logger.debug("sql_string(%d)='%s'", len(sql_string), sql_string)
     if sql_string == "":
-        raise ValueError(f"No fields have been set, but method invoked, domain='{domain}'")
+        raise ValueError(f"No fields have been set, but function invoked, domain='{domain}'")
 
     # Set last_updated to current timestamp
     fields.append(time.time())
@@ -177,7 +177,7 @@ def add(domain: str, origin: str, command: str, path: str = None, software: str
     elif origin is not None and not validators.domain(origin.split("/")[0]):
         raise ValueError(f"Bad origin name='{origin}'")
     elif blacklist.is_blacklisted(domain):
-        raise Exception(f"domain='{domain}' is blacklisted, but method invoked")
+        raise Exception(f"domain='{domain}' is blacklisted, but function invoked")
     elif domain.find("/profile/") > 0 or domain.find("/users/") > 0 or (is_registered(domain.split("/")[0]) and domain.find("/c/") > 0):
         raise Exception(f"domain='{domain}' is a single user")
     elif domain.find("/tag/") > 0:
@@ -217,7 +217,7 @@ def add(domain: str, origin: str, command: str, path: str = None, software: str
     logger.debug("Checking if domain='%s' has pending updates ...", domain)
     if has_pending(domain):
         logger.debug("Flushing updates for domain='%s' ...", domain)
-        update_data(domain)
+        update(domain)
 
     logger.debug("EXIT!")
 
@@ -301,7 +301,7 @@ def is_recent(domain: str, column: str = "last_instance_fetch") -> bool:
 
     if not isinstance(column, str):
         raise ValueError(f"Parameter column[]='{type(column)}' is not of type 'str'")
-    elif column not in ["last_instance_fetch", "last_blocked", "last_nodeinfo"]:
+    elif not column.startswith("last_"):
         raise ValueError(f"Parameter column='{column}' is not expected")
     elif not is_registered(domain):
         logger.debug("domain='%s' is not registered, returning False - EXIT!", domain)
@@ -315,7 +315,10 @@ def is_recent(domain: str, column: str = "last_instance_fetch") -> bool:
     database.cursor.execute(f"SELECT {column} FROM instances WHERE domain = ? LIMIT 1", [domain])
 
     # Fetch row
-    fetched = float(database.cursor.fetchone()[column])
+    row = database.cursor.fetchone()
+
+    fetched = float(row[column]) if row[column] is not None else 0.0
+
     diff = (time.time() - fetched)
 
     logger.debug("fetched[%s]='%s',key='%s',diff=%f", type(fetched), fetched, key, diff)
@@ -421,7 +424,7 @@ def set_obfuscated_blocks(domain: str, obfuscated: int):
     domain_helper.raise_on(domain)
 
     if not isinstance(obfuscated, int):
-        raise ValueError(f"Parameter obfuscated[]='{type(blocks)}' is not of type 'int'")
+        raise ValueError(f"Parameter obfuscated[]='{type(obfuscated)}' is not of type 'int'")
     elif obfuscated < 0:
         raise ValueError(f"Parameter obfuscated={obfuscated} is not valid")