mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-20 20:16:35 +00:00
Merge 2f0bdfd8da
into f5a71592fc
This commit is contained in:
commit
e45c24ecc3
@ -4,7 +4,7 @@ from django.utils.translation import gettext_lazy as _
|
|||||||
from background_task.models import Task
|
from background_task.models import Task
|
||||||
from common.logger import log
|
from common.logger import log
|
||||||
from sync.models import Source
|
from sync.models import Source
|
||||||
from sync.tasks import index_source_task, check_source_directory_exists
|
from sync.tasks import check_source_directory_exists
|
||||||
|
|
||||||
|
|
||||||
class Command(BaseCommand):
|
class Command(BaseCommand):
|
||||||
@ -23,15 +23,6 @@ class Command(BaseCommand):
|
|||||||
str(source.pk),
|
str(source.pk),
|
||||||
verbose_name=verbose_name.format(source.name),
|
verbose_name=verbose_name.format(source.name),
|
||||||
)
|
)
|
||||||
# Recreate the initial indexing task
|
|
||||||
log.info(f'Resetting tasks for source: {source}')
|
|
||||||
verbose_name = _('Index media from source "{}"')
|
|
||||||
index_source_task(
|
|
||||||
str(source.pk),
|
|
||||||
repeat=source.index_schedule,
|
|
||||||
schedule=source.task_run_at_dt,
|
|
||||||
verbose_name=verbose_name.format(source.name),
|
|
||||||
)
|
|
||||||
# This also chains down to call each Media objects .save() as well
|
# This also chains down to call each Media objects .save() as well
|
||||||
source.save()
|
source.save()
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ def source_pre_save(sender, instance, **kwargs):
|
|||||||
verbose_name = _('Index media from source "{}"')
|
verbose_name = _('Index media from source "{}"')
|
||||||
index_source_task(
|
index_source_task(
|
||||||
str(instance.pk),
|
str(instance.pk),
|
||||||
repeat=instance.index_schedule,
|
repeat=0,
|
||||||
schedule=instance.task_run_at_dt,
|
schedule=instance.task_run_at_dt,
|
||||||
verbose_name=verbose_name.format(instance.name),
|
verbose_name=verbose_name.format(instance.name),
|
||||||
)
|
)
|
||||||
@ -118,7 +118,7 @@ def source_post_save(sender, instance, created, **kwargs):
|
|||||||
verbose_name = _('Index media from source "{}"')
|
verbose_name = _('Index media from source "{}"')
|
||||||
index_source_task(
|
index_source_task(
|
||||||
str(instance.pk),
|
str(instance.pk),
|
||||||
repeat=instance.index_schedule,
|
repeat=0,
|
||||||
schedule=600,
|
schedule=600,
|
||||||
verbose_name=verbose_name.format(instance.name),
|
verbose_name=verbose_name.format(instance.name),
|
||||||
)
|
)
|
||||||
|
@ -28,7 +28,7 @@ from background_task import background
|
|||||||
from background_task.exceptions import InvalidTaskError
|
from background_task.exceptions import InvalidTaskError
|
||||||
from background_task.models import Task, CompletedTask
|
from background_task.models import Task, CompletedTask
|
||||||
from django_huey import db_periodic_task, db_task, task as huey_task # noqa
|
from django_huey import db_periodic_task, db_task, task as huey_task # noqa
|
||||||
from huey import CancelExecution
|
from huey import CancelExecution, crontab as huey_crontab
|
||||||
from common.huey import dynamic_retry
|
from common.huey import dynamic_retry
|
||||||
from common.logger import log
|
from common.logger import log
|
||||||
from common.errors import ( BgTaskWorkerError, DownloadFailedException,
|
from common.errors import ( BgTaskWorkerError, DownloadFailedException,
|
||||||
@ -36,7 +36,7 @@ from common.errors import ( BgTaskWorkerError, DownloadFailedException,
|
|||||||
NoThumbnailException, )
|
NoThumbnailException, )
|
||||||
from common.utils import ( django_queryset_generator as qs_gen,
|
from common.utils import ( django_queryset_generator as qs_gen,
|
||||||
remove_enclosed, seconds_to_timestr, )
|
remove_enclosed, seconds_to_timestr, )
|
||||||
from .choices import Val, TaskQueue
|
from .choices import Val, IndexSchedule, TaskQueue
|
||||||
from .models import Source, Media, MediaServer, Metadata
|
from .models import Source, Media, MediaServer, Metadata
|
||||||
from .utils import get_remote_image, resize_image_to_height, filter_response
|
from .utils import get_remote_image, resize_image_to_height, filter_response
|
||||||
from .youtube import YouTubeError
|
from .youtube import YouTubeError
|
||||||
@ -222,6 +222,39 @@ def save_model(instance):
|
|||||||
time.sleep(random.expovariate(arg))
|
time.sleep(random.expovariate(arg))
|
||||||
|
|
||||||
|
|
||||||
|
@db_periodic_task(
|
||||||
|
huey_crontab(minute=59, strict=True,),
|
||||||
|
priority=100,
|
||||||
|
expires=30*60,
|
||||||
|
queue=Val(TaskQueue.DB),
|
||||||
|
)
|
||||||
|
def schedule_indexing():
|
||||||
|
now = timezone.now()
|
||||||
|
next_hour = now + timezone.timedelta(hours=1, minutes=1)
|
||||||
|
qs = Source.objects.filter(
|
||||||
|
index_schedule__gt=Val(IndexSchedule.NEVER),
|
||||||
|
)
|
||||||
|
for source in qs_gen(qs):
|
||||||
|
previous_run = next_hour - timezone.timedelta(
|
||||||
|
seconds=source.index_schedule
|
||||||
|
)
|
||||||
|
skip_source = (
|
||||||
|
not source.is_active or
|
||||||
|
source.target_schedule >= next_hour or
|
||||||
|
source.last_crawl >= previous_run
|
||||||
|
)
|
||||||
|
if skip_source:
|
||||||
|
continue
|
||||||
|
log.info(f'Scheduling an indexing task for source "{source.name}": {source.pk}')
|
||||||
|
vn_fmt = _('Index media from source "{}"')
|
||||||
|
index_source_task(
|
||||||
|
str(source.pk),
|
||||||
|
repeat=0,
|
||||||
|
schedule=600,
|
||||||
|
verbose_name=vn_fmt.format(source.name),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def schedule_media_servers_update():
|
def schedule_media_servers_update():
|
||||||
# Schedule a task to update media servers
|
# Schedule a task to update media servers
|
||||||
log.info('Scheduling media server updates')
|
log.info('Scheduling media server updates')
|
||||||
|
@ -999,14 +999,6 @@ class ResetTasks(FormView):
|
|||||||
str(source.pk),
|
str(source.pk),
|
||||||
verbose_name=verbose_name.format(source.name),
|
verbose_name=verbose_name.format(source.name),
|
||||||
)
|
)
|
||||||
# Recreate the initial indexing task
|
|
||||||
verbose_name = _('Index media from source "{}"')
|
|
||||||
index_source_task(
|
|
||||||
str(source.pk),
|
|
||||||
repeat=source.index_schedule,
|
|
||||||
schedule=source.task_run_at_dt,
|
|
||||||
verbose_name=verbose_name.format(source.name)
|
|
||||||
)
|
|
||||||
# This also chains down to call each Media objects .save() as well
|
# This also chains down to call each Media objects .save() as well
|
||||||
source.save()
|
source.save()
|
||||||
return super().form_valid(form)
|
return super().form_valid(form)
|
||||||
|
Loading…
Reference in New Issue
Block a user