Source code for ferrosoft.apps.ferrobase.management.commands.ferrobase_cleanup

from django.core.management.base import BaseCommand

from ferrosoft.apps.ferrobase.models import Tenant
from ferrosoft.apps.ferrobase.services.cleanup import CleanupService


[docs] class Command(BaseCommand): """Management command that removes stale resources from all databases. Runs ``CleanupService`` against the master database first, then against every active tenant database in alphabetical order. """ help = "Clean up old resources."
[docs] def handle(self, *args, **options): service = CleanupService() service.cleanup_master_database() for tenant in Tenant.all_ordered(): self.stderr.write( self.style.NOTICE("Cleaning up resources for tenant %s" % tenant.name) ) service.cleanup_tenant_database(tenant)