import inspect
import json
import logging
+import numpy
import time
from urllib.parse import urlparse
logger = logging.getLogger(__name__)
#logger.setLevel(logging.DEBUG)
+default_rng = numpy.random.default_rng()
+
def check_instance(args: argparse.Namespace) -> int:
logger.debug("args.domain='%s' - CALLED!", args.domain)
logger.debug("raw[%s]()=%d", type(raw), len(raw))
if "exception" in raw:
- logger.warning("row[domain]='%s' has caused an exception: '%s' - raising again ...", row["domain"], type(raw["exception"]))
+ logger.warning("source_domain='%s' has caused an exception: '%s' - raising again ...", raw["domain"], type(raw["exception"]))
raise raw["exception"]
elif "error_message" in raw:
- logger.warning("row[domain]='%s' has caused error message: '%s' - SKIPPED!", row["domain"], raw["error_message"])
+ logger.warning("source_domain='%s' has caused error message: '%s' - SKIPPED!", raw["domain"], raw["error_message"])
continue
elif not "data" in raw["json"]:
logger.warning("Cannot find key 'nodes' in raw[json]()=%d", len(raw["json"]))
logger.info("Fetching instances for domain='%s',software='%s' ...", domain, software)
federation.fetch_instances(domain, None, None, inspect.currentframe().f_code.co_name)
+ logger.debug("Random sleep to mitigate source's automatic blocking (sorry) ...")
+ time.sleep(default_rng.integers(low=1, high=3))
+
logger.debug("Success! - EXIT!")
return 0
logger.debug("Invoking instances.set_last_error(%s,%s) ...", domain, exception)
instances.set_last_error(domain, exception)
- raise exception
+ logger.debug("Returning json_reply(%d)[]='%s' during an exception: '%s' - EXIT!", len(json_reply), type(json_reply), exception)
+ return json_reply
logger.debug("response.ok='%s',response.status_code=%d,response.reason='%s'", response.ok, response.status_code, response.reason)
if not response.ok or response.status_code > 200:
def fetch_json_rows(hostname: str, path: str, headers: dict = {}, rows_key: str = None):
logger.debug("hostname='%s',path='%s',headers()=%d,rows_key='%s' - CALLED!", hostname, path, len(headers), rows_key)
+
if not isinstance(hostname, str):
raise ValueError(f"hostname[]='{type(hostname)}' is not of type 'str'")
elif hostname == "":