From 012e28d4effbffb75352bdb8cfed41a57732d1c0 Mon Sep 17 00:00:00 2001 From: simon Date: Thu, 2 Dec 2021 15:54:29 +0700 Subject: [PATCH] initial beat scheduler setup --- run.sh | 1 + tubearchivist/home/config.json | 7 +++++++ tubearchivist/home/tasks.py | 21 +++++++++++++++------ 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/run.sh b/run.sh index 641baf0..827d109 100644 --- a/run.sh +++ b/run.sh @@ -36,4 +36,5 @@ export DJANGO_SUPERUSER_PASSWORD=$TA_PASSWORD && \ python manage.py collectstatic --noinput -c nginx & celery -A home.tasks worker --loglevel=INFO & +celery -A home beat --loglevel=INFO & uwsgi --ini uwsgi.ini diff --git a/tubearchivist/home/config.json b/tubearchivist/home/config.json index e5ecc38..6b1b5d2 100644 --- a/tubearchivist/home/config.json +++ b/tubearchivist/home/config.json @@ -29,5 +29,12 @@ "videos": "/youtube", "file_template": "%(id)s_%(title)s.mp4", "colors": "dark" + }, + "scheduler": { + "update_subscribed": false, + "download_pending": false, + "check_reindex": false, + "thumbnail_check": false, + "run_backup": false } } diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index b5bb3fb..ac78f0d 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -9,7 +9,7 @@ Functionality: import os from celery import Celery, shared_task -from home.src.config import AppConfig +from home.src.config import AppConfig, ScheduleBuilder from home.src.download import ( ChannelSubscription, PendingList, @@ -30,13 +30,13 @@ CONFIG = AppConfig().config REDIS_HOST = os.environ.get("REDIS_HOST") REDIS_PORT = os.environ.get("REDIS_PORT") or 6379 -os.environ.setdefault("DJANGO_SETTINGS_MODULE", "home.settings") +os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings") app = Celery("tasks", broker=f"redis://{REDIS_HOST}:{REDIS_PORT}") app.config_from_object("django.conf:settings", namespace="ta:") app.autodiscover_tasks() -@shared_task +@shared_task(name="update_subscribed") def update_subscribed(): """look for missing videos and add to pending""" message = { @@ -58,7 +58,7 @@ def update_subscribed(): check_reindex.delay() -@shared_task +@shared_task(name="download_pending") def download_pending(): """download latest pending videos""" have_lock = False @@ -120,7 +120,7 @@ def extrac_dl(youtube_ids): thumb_handler.download_vid(all_videos_added) -@shared_task +@shared_task(name="check_reindex") def check_reindex(): """run the reindex main command""" reindex_old_documents() @@ -148,7 +148,7 @@ def run_manual_import(): my_lock.release() -@shared_task +@shared_task(name="run_backup") def run_backup(): """called from settings page, dump backup to zip file""" backup_all_indexes() @@ -193,6 +193,12 @@ def rescan_filesystem(): validate_thumbnails() +@shared_task(name="thumbnail_check") +def thumbnail_check(): + """validate thumbnails""" + validate_thumbnails() + + @shared_task def re_sync_thumbs(): """sync thumbnails to mediafiles""" @@ -269,3 +275,6 @@ def index_channel_playlists(channel_id): handler.download_playlist(missing_playlists) return + + +app.conf.beat_schedule = ScheduleBuilder().build_schedule()