ref: avoid double nodinfo retrieve
parent
9419d1e3e5
commit
ee22c5d145
|
@ -35,6 +35,8 @@ class InstanceInfo():
|
|||
return
|
||||
|
||||
self.node_info = InstanceInfo.get_nodeinfo(domain,req_timeout=self._req_timeout)
|
||||
|
||||
def get_instance_info(self):
|
||||
try:
|
||||
self.parse_instance_info()
|
||||
except Exception as err:
|
||||
|
@ -190,9 +192,10 @@ class InstanceInfo():
|
|||
self.open_registrations = self.node_info.get("openRegistrations", False)
|
||||
|
||||
def discover_info(self):
|
||||
# Mastodon API
|
||||
site = requests.get(f"https://{self.domain}/api/v1/instance",timeout=self._req_timeout,allow_redirects=False)
|
||||
if site.status_code != 200:
|
||||
raise Exception(f"Unexpected status code retrieved when discovering nodeinfo: {site.status_code}")
|
||||
raise Exception(f"Unexpected status code retrieved when discovering instance info: {site.status_code}")
|
||||
self.instance_info = site.json()
|
||||
self.approval_required = self.instance_info.get("approval_required")
|
||||
if self.node_info is None:
|
||||
|
@ -225,6 +228,8 @@ class InstanceInfo():
|
|||
"mitra": self.get_firefish_info,
|
||||
"unknown": self.get_unknown_info,
|
||||
"wildcard": self.get_unknown_info,
|
||||
# Instance info not supported for misskey yet
|
||||
"misskey": self.get_unknown_info,
|
||||
}
|
||||
if self.software not in software_map:
|
||||
self.discover_info()
|
||||
|
@ -260,7 +265,8 @@ class InstanceInfo():
|
|||
raise Exception(f"Status code unexpected for instance frontpage: {req.status_code}")
|
||||
|
||||
# Debug
|
||||
# ii = InstanceInfo("lemmy.dbzer0.com")
|
||||
# ii = InstanceInfo("makai.chaotic.ninja")
|
||||
# ii.get_instance_info()
|
||||
# logger.debug([
|
||||
# ii.software,
|
||||
# ii.open_registrations,
|
||||
|
|
|
@ -187,7 +187,9 @@ class ActivityPubPM:
|
|||
admins = database.find_admins_by_instance(instance)
|
||||
if not admins:
|
||||
try:
|
||||
admins = InstanceInfo(domain).admin_usernames
|
||||
ii = InstanceInfo(domain)
|
||||
ii.get_instance_info()
|
||||
admins = ii.admin_usernames
|
||||
except Exception as err:
|
||||
if software not in SUPPORTED_SOFTWARE:
|
||||
logger.warning(f"Failed to figure out admins from {software}: {domain}")
|
||||
|
|
|
@ -10,12 +10,12 @@ def ensure_instance_registered(domain, allow_unreachable=False, record_unreachab
|
|||
instance = database.find_instance_by_domain(domain)
|
||||
try:
|
||||
instance_info = InstanceInfo(domain,allow_unreachable=allow_unreachable, req_timeout=allowed_timeout)
|
||||
instance_info.get_instance_info()
|
||||
except Exception as err:
|
||||
if record_unreachable and instance and instance.software != "wildcard":
|
||||
# We only consider an instance unreachable if we can't reach its nodeinfo
|
||||
# This means that a misconfigured instance will also be considered as 'down'
|
||||
nodeinfo = InstanceInfo.get_nodeinfo(domain,req_timeout=allowed_timeout)
|
||||
if nodeinfo is None:
|
||||
if instance_info.node_info is None:
|
||||
logger.warning(f"Recorded {domain} as unreachable.")
|
||||
instance.updated = datetime.utcnow()
|
||||
instance.poll_failures += 1
|
||||
|
|
|
@ -47,7 +47,8 @@ if __name__ == "__main__":
|
|||
for instance in database.get_all_instances(0,0):
|
||||
if instance.software == 'wildcard':
|
||||
continue
|
||||
if instance.poll_failures > int(os.getenv('FEDISEER_IGNORE_POLL_FAILS', 0)):
|
||||
# -1 doesn't skip anything
|
||||
if os.getenv('FEDISEER_IGNORE_POLL_FAILS', -1) >= 0 and instance.poll_failures > int(os.getenv('FEDISEER_IGNORE_POLL_FAILS', 0)):
|
||||
logger.debug(f"Skipped {instance.domain} due to too many poll fails.")
|
||||
continue
|
||||
futures.append(executor.submit(refresh_info, instance.domain))
|
||||
|
|
Loading…
Reference in New Issue