diff --git a/engine/apps/grafana_plugin/tasks/sync.py b/engine/apps/grafana_plugin/tasks/sync.py index c33c8541..829fb923 100644 --- a/engine/apps/grafana_plugin/tasks/sync.py +++ b/engine/apps/grafana_plugin/tasks/sync.py @@ -166,26 +166,13 @@ def cleanup_empty_deleted_integrations(organization_pk, dry_run=True): integration.hard_delete() -@shared_dedicated_queue_retry_task(autoretry_for=(Exception,), max_retries=0) -def start_cleanup_organizations(): - # TODO: Remove next release after tasks revoked - cleanup_threshold = timezone.now() - INACTIVE_PERIOD - organization_qs = Organization.objects.filter(last_time_synced__lte=cleanup_threshold) - organization_pks = organization_qs.values_list("pk", flat=True) - logger.debug(f"Found {len(organization_pks)} organizations") - max_countdown = CLEANUP_PERIOD.seconds - for idx, organization_pk in enumerate(organization_pks): - countdown = idx % max_countdown # Spread orgs evenly - cleanup_organization_async.apply_async((organization_pk,), countdown=countdown) - - @shared_dedicated_queue_retry_task(autoretry_for=(Exception,), max_retries=0) def start_cleanup_deleted_integrations(): cleanup_threshold = timezone.now() - CLEANUP_PERIOD channels_qs = AlertReceiveChannel.objects_with_deleted.filter(deleted_at__gte=cleanup_threshold) organization_pks = set(channels_qs.values_list("organization_id", flat=True)) logger.debug(f"Found {len(organization_pks)} organizations") - for organization_pk in enumerate(organization_pks): + for _, organization_pk in enumerate(organization_pks): cleanup_empty_deleted_integrations.apply_async( (organization_pk, False), ) diff --git a/engine/settings/celery_task_routes.py b/engine/settings/celery_task_routes.py index ea866c1a..cce98b6f 100644 --- a/engine/settings/celery_task_routes.py +++ b/engine/settings/celery_task_routes.py @@ -145,7 +145,6 @@ CELERY_TASK_ROUTES = { "apps.chatops_proxy.tasks.sync_org_with_chatops_proxy": {"queue": "long"}, "apps.grafana_plugin.tasks.sync.cleanup_organization_async": {"queue": "long"}, "apps.grafana_plugin.tasks.sync.cleanup_empty_deleted_integrations": {"queue": "long"}, - "apps.grafana_plugin.tasks.sync.start_cleanup_organizations": {"queue": "long"}, "apps.grafana_plugin.tasks.sync.start_cleanup_deleted_integrations": {"queue": "long"}, "apps.grafana_plugin.tasks.sync.start_cleanup_deleted_organizations": {"queue": "long"}, "apps.grafana_plugin.tasks.sync.start_sync_organizations": {"queue": "long"},