diff --git a/api/tacticalrmm/core/management/commands/post_update_tasks.py b/api/tacticalrmm/core/management/commands/post_update_tasks.py index 3a7d259a87..224216e575 100644 --- a/api/tacticalrmm/core/management/commands/post_update_tasks.py +++ b/api/tacticalrmm/core/management/commands/post_update_tasks.py @@ -1,5 +1,6 @@ import base64 +from django.core.management import call_command from django.core.management.base import BaseCommand from accounts.models import User @@ -54,4 +55,6 @@ def handle(self, *args, **kwargs) -> None: agent.save(update_fields=["goarch"]) + call_command("remove_orphaned_history_results") + call_command("sync_mesh_with_trmm") self.stdout.write("Post update tasks finished") diff --git a/api/tacticalrmm/core/tasks.py b/api/tacticalrmm/core/tasks.py index 70e9157f15..6b74e462f4 100644 --- a/api/tacticalrmm/core/tasks.py +++ b/api/tacticalrmm/core/tasks.py @@ -7,7 +7,7 @@ import nats from django.conf import settings -from django.db import transaction +from django.core.management import call_command from django.db.models import Prefetch from django.db.utils import DatabaseError from django.utils import timezone as djangotime @@ -20,7 +20,7 @@ from alerts.models import Alert from alerts.tasks import prune_resolved_alerts from autotasks.models import AutomatedTask, TaskResult -from checks.models import Check, CheckHistory, CheckResult +from checks.models import Check, CheckResult from checks.tasks import prune_check_history from clients.models import Client, Site from core.mesh_utils import ( @@ -68,15 +68,7 @@ def core_maintenance_tasks() -> None: remove_if_not_scheduled=True, expire_date__lt=djangotime.now() ).delete() - with transaction.atomic(): - check_hist_agentids = CheckHistory.objects.values_list( - "agent_id", flat=True - ).distinct() - current_agentids = set(Agent.objects.values_list("agent_id", flat=True)) - orphaned_agentids = [ - i for i in check_hist_agentids if i not in current_agentids - ] - CheckHistory.objects.filter(agent_id__in=orphaned_agentids).delete() + call_command("remove_orphaned_history_results") core = get_core_settings() diff --git a/update.sh b/update.sh index 9e80a63b44..b881b5a246 100644 --- a/update.sh +++ b/update.sh @@ -407,7 +407,6 @@ python manage.py create_installer_user python manage.py create_natsapi_conf python manage.py create_uwsgi_conf python manage.py clear_redis_celery_locks -python manage.py sync_mesh_with_trmm python manage.py post_update_tasks echo "Running management commands...please wait..." API=$(python manage.py get_config api)