From 972c184c701a539c2491f3e364994299ba465a53 Mon Sep 17 00:00:00 2001 From: meeb Date: Sun, 7 Mar 2021 13:39:49 +1100 Subject: [PATCH] add longer source indexing options and a never option, resolves #68 --- tubesync/sync/models.py | 5 ++++- tubesync/sync/signals.py | 23 ++++++++++++----------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 1f2c315..d7b6cf7 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -158,6 +158,9 @@ class Source(models.Model): EVERY_6_HOURS = 21600, _('Every 6 hours') EVERY_12_HOURS = 43200, _('Every 12 hours') EVERY_24_HOURS = 86400, _('Every 24 hours') + EVERY_3_DAYS = 259200, _('Every 3 days') + EVERY_7_DAYS = 604800, _('Every 7 days') + NEVER = 0, _('Never') uuid = models.UUIDField( _('uuid'), @@ -218,7 +221,7 @@ class Source(models.Model): _('index schedule'), choices=IndexSchedule.choices, db_index=True, - default=IndexSchedule.EVERY_6_HOURS, + default=IndexSchedule.EVERY_24_HOURS, help_text=_('Schedule of how often to index the source for new media') ) download_media = models.BooleanField( diff --git a/tubesync/sync/signals.py b/tubesync/sync/signals.py index 1cb1852..acb1300 100644 --- a/tubesync/sync/signals.py +++ b/tubesync/sync/signals.py @@ -47,17 +47,18 @@ def source_post_save(sender, instance, created, **kwargs): priority=0, verbose_name=verbose_name.format(instance.name) ) - delete_task_by_source('sync.tasks.index_source_task', instance.pk) - log.info(f'Scheduling media indexing for source: {instance.name}') - verbose_name = _('Index media from source "{}"') - index_source_task( - str(instance.pk), - repeat=instance.index_schedule, - queue=str(instance.pk), - priority=5, - verbose_name=verbose_name.format(instance.name), - remove_existing_tasks=True - ) + if instance.index_schedule > 0: + delete_task_by_source('sync.tasks.index_source_task', instance.pk) + log.info(f'Scheduling media indexing for source: {instance.name}') + verbose_name = _('Index media from source "{}"') + index_source_task( + str(instance.pk), + repeat=instance.index_schedule, + queue=str(instance.pk), + priority=5, + verbose_name=verbose_name.format(instance.name), + remove_existing_tasks=True + ) # Trigger the post_save signal for each media item linked to this source as various # flags may need to be recalculated for media in Media.objects.filter(source=instance):