This commit is contained in:
tcely 2025-06-15 19:22:43 +00:00 committed by GitHub
commit 775ab255f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 12 additions and 23 deletions

View File

@ -1,6 +1,6 @@
from django.core.management.base import BaseCommand, CommandError # noqa
from django.db.transaction import atomic
from django.utils.translation import gettext_lazy as _
from django.utils.translation import gettext_lazy as _ # noqa
from background_task.models import Task
from common.logger import log
from sync.models import Source
@ -18,11 +18,7 @@ class Command(BaseCommand):
Task.objects.all().delete()
# Iter all sources, creating new tasks
for source in Source.objects.all():
verbose_name = _('Check download directory exists for source "{}"')
check_source_directory_exists(
str(source.pk),
verbose_name=verbose_name.format(source.name),
)
check_source_directory_exists(str(source.pk))
# Recreate the initial indexing task
log.info(f'Resetting tasks for source: {source}')
verbose_name = _('Index media from source "{}"')

View File

@ -34,7 +34,7 @@ def source_pre_save(sender, instance, **kwargs):
return
args = ( str(instance.pk), )
check_source_directory_exists.now(*args)
check_source_directory_exists.call_local(*args)
existing_dirpath = existing_source.directory_path.resolve(strict=True)
new_dirpath = instance.directory_path.resolve(strict=False)
if existing_dirpath != new_dirpath:
@ -105,11 +105,7 @@ def source_pre_save(sender, instance, **kwargs):
def source_post_save(sender, instance, created, **kwargs):
# Check directory exists and create an indexing task for newly created sources
if created:
verbose_name = _('Check download directory exists for source "{}"')
check_source_directory_exists(
str(instance.pk),
verbose_name=verbose_name.format(instance.name),
)
check_source_directory_exists(str(instance.pk))
if instance.source_type != Val(YouTube_SourceType.PLAYLIST) and instance.copy_channel_images:
download_source_images(str(instance.pk))
if instance.index_schedule > 0:
@ -139,7 +135,6 @@ def source_pre_delete(sender, instance, **kwargs):
instance.deactivate()
log.info(f'Deleting tasks for source: {instance.name}')
delete_task_by_source('sync.tasks.index_source_task', instance.pk)
delete_task_by_source('sync.tasks.check_source_directory_exists', instance.pk)
delete_task_by_source('sync.tasks.rename_all_media_for_source', instance.pk)
delete_task_by_source('sync.tasks.save_all_media_for_source', instance.pk)
@ -166,7 +161,6 @@ def source_post_delete(sender, instance, **kwargs):
source = instance
log.info(f'Deleting tasks for removed source: {source.name}')
delete_task_by_source('sync.tasks.index_source_task', instance.pk)
delete_task_by_source('sync.tasks.check_source_directory_exists', instance.pk)
delete_task_by_source('sync.tasks.rename_all_media_for_source', instance.pk)
delete_task_by_source('sync.tasks.save_all_media_for_source', instance.pk)

View File

@ -61,7 +61,6 @@ def map_task_to_instance(task):
TASK_MAP = {
'sync.tasks.migrate_to_metadata': Media,
'sync.tasks.index_source_task': Source,
'sync.tasks.check_source_directory_exists': Source,
'sync.tasks.download_media_thumbnail': Media,
'sync.tasks.download_media': Media,
'sync.tasks.download_media_metadata': Media,
@ -536,7 +535,7 @@ def index_source_task(source_id):
)
@background(schedule=dict(priority=0, run_at=0), queue=Val(TaskQueue.FS))
@dynamic_retry(db_task, priority=100, retries=15, queue=Val(TaskQueue.FS))
def check_source_directory_exists(source_id):
'''
Checks the output directory for a source exists and is writable, if it does
@ -547,7 +546,7 @@ def check_source_directory_exists(source_id):
source = Source.objects.get(pk=source_id)
except Source.DoesNotExist as e:
# Task triggered but the Source has been deleted, delete the task
raise InvalidTaskError(_('no such source')) from e
raise CancelExecution(_('no such source'), retry=False) from e
# Check the source output directory exists
if not source.directory_exists():
# Try to create it

View File

@ -212,7 +212,7 @@ class FrontEndTestCase(TestCase):
args=(source_uuid,))[0]
self.assertEqual(task.queue, Val(TaskQueue.NET))
# Run the check_source_directory_exists task
check_source_directory_exists.now(source_uuid)
check_source_directory_exists.call_local(source_uuid)
# Check the source is now on the source overview page
response = c.get('/sources')
self.assertEqual(response.status_code, 200)

View File

@ -994,11 +994,7 @@ class ResetTasks(FormView):
Task.objects.all().delete()
# Iter all tasks
for source in Source.objects.all():
verbose_name = _('Check download directory exists for source "{}"')
check_source_directory_exists(
str(source.pk),
verbose_name=verbose_name.format(source.name),
)
check_source_directory_exists(str(source.pk))
# Recreate the initial indexing task
verbose_name = _('Index media from source "{}"')
index_source_task(

View File

@ -57,12 +57,16 @@ DJANGO_HUEY = {
'limited': sqlite_tasks('limited', prefix='net'),
'network': sqlite_tasks('network'),
},
'verbose': None if 'true' == getenv('TUBESYNC_DEBUG', False).strip().lower() else False,
}
for django_huey_queue in DJANGO_HUEY['queues'].values():
connection = django_huey_queue.get('connection')
if connection:
filepath = Path('/.' + connection.get('filename') or '').resolve(strict=False)
filepath.parent.mkdir(exist_ok=True, parents=True)
consumer = django_huey_queue.get('consumer')
if consumer:
consumer['verbose'] = DJANGO_HUEY.get('verbose', False)
TEMPLATES = [