diff --git a/mastodon/jobs.py b/mastodon/jobs.py index 12b14b85..8f7703c0 100644 --- a/mastodon/jobs.py +++ b/mastodon/jobs.py @@ -1,5 +1,6 @@ from datetime import timedelta +from django.db.models import Q from django.utils import timezone from loguru import logger @@ -17,14 +18,20 @@ def run(self): count_checked = 0 count_unreachable = 0 count_disabled = 0 - for site in MastodonApplication.objects.exclude(disabled=True): + q = Q(last_reachable_date__lte=timezone.now() - timedelta(days=1)) | Q( + last_reachable_date__isnull=True + ) + for site in MastodonApplication.objects.exclude(disabled=True).filter(q): domain = None count_checked += 1 try: - domain, api_domain, v = detect_server_info(site.domain_name) + api_domain = site.api_domain or site.domain_name + domain, api_domain, v = detect_server_info(api_domain) site.last_reachable_date = timezone.now() except: - logger.warning(f"Failed to detect server info for {site.domain_name}") + logger.warning( + f"Failed to detect server info for {site.domain_name}/{site.api_domain}" + ) count_unreachable += 1 if site.last_reachable_date is None: site.last_reachable_date = timezone.now() - timedelta(days=1)