Use tasks.schedule_media_servers_update

This commit is contained in:
tcely authored and GitHub committed 2025-03-19 08:37:29 -04:00
1 parent d3e544def2
commit 2484a30900
1 file changed
+9 -18
@@ -2,19 +2,18 @@ import os
import uuid import uuid
from django.utils.translation import gettext_lazy as _ from django.utils.translation import gettext_lazy as _
from django.core.management.base import BaseCommand, CommandError from django.core.management.base import BaseCommand, CommandError
from django.db.models import signals from django.db.transaction import atomic
from common.logger import log from common.logger import log
from sync.models import Source, Media, MediaServer from sync.models import Source, Media, MediaServer
from sync.signals import media_post_delete from sync.tasks import schedule_media_servers_update
from sync.tasks import rescan_media_server
class Command(BaseCommand): class Command(BaseCommand):
help = ('Deletes a source by UUID') help = _('Deletes a source by UUID')
def add_arguments(self, parser): def add_arguments(self, parser):
parser.add_argument('--source', action='store', required=True, help='Source UUID') parser.add_argument('--source', action='store', required=True, help=_('Source UUID'))
def handle(self, *args, **options): def handle(self, *args, **options):
source_uuid_str = options.get('source', '') source_uuid_str = options.get('source', '')
@@ -30,22 +29,14 @@ class Command(BaseCommand):
raise CommandError(f'Source does not exist with ' raise CommandError(f'Source does not exist with '
f'UUID: {source_uuid}') f'UUID: {source_uuid}')
# Reconfigure the source to not update the disk or media servers # Reconfigure the source to not update the disk or media servers
source.deactivate() with atomic(durable=True):
source.deactivate()
# Delete the source, triggering pre-delete signals for each media item # Delete the source, triggering pre-delete signals for each media item
log.info(f'Found source with UUID "{source.uuid}" with name ' log.info(f'Found source with UUID "{source.uuid}" with name '
f'"{source.name}" and deleting it, this may take some time!') f'"{source.name}" and deleting it, this may take some time!')
log.info(f'Source directory: {source.directory_path}') log.info(f'Source directory: {source.directory_path}')
source.delete() with atomic(durable=True):
# Update any media servers source.delete()
for mediaserver in MediaServer.objects.all(): schedule_media_servers_update()
log.info(f'Scheduling media server updates')
verbose_name = _('Request media server rescan for "{}"')
rescan_media_server(
str(mediaserver.pk),
priority=0,
schedule=30,
verbose_name=verbose_name.format(mediaserver),
remove_existing_tasks=True
)
# All done # All done
log.info('Done') log.info('Done')