initial beat scheduler setup

This commit is contained in:
simon 2021-12-02 15:54:29 +07:00
parent 3cc5db7ad1
commit 012e28d4ef
No known key found for this signature in database
GPG Key ID: 2C15AA5E89985DD4
3 changed files with 23 additions and 6 deletions

1
run.sh
View File

@ -36,4 +36,5 @@ export DJANGO_SUPERUSER_PASSWORD=$TA_PASSWORD && \
python manage.py collectstatic --noinput -c python manage.py collectstatic --noinput -c
nginx & nginx &
celery -A home.tasks worker --loglevel=INFO & celery -A home.tasks worker --loglevel=INFO &
celery -A home beat --loglevel=INFO &
uwsgi --ini uwsgi.ini uwsgi --ini uwsgi.ini

View File

@ -29,5 +29,12 @@
"videos": "/youtube", "videos": "/youtube",
"file_template": "%(id)s_%(title)s.mp4", "file_template": "%(id)s_%(title)s.mp4",
"colors": "dark" "colors": "dark"
},
"scheduler": {
"update_subscribed": false,
"download_pending": false,
"check_reindex": false,
"thumbnail_check": false,
"run_backup": false
} }
} }

View File

@ -9,7 +9,7 @@ Functionality:
import os import os
from celery import Celery, shared_task from celery import Celery, shared_task
from home.src.config import AppConfig from home.src.config import AppConfig, ScheduleBuilder
from home.src.download import ( from home.src.download import (
ChannelSubscription, ChannelSubscription,
PendingList, PendingList,
@ -30,13 +30,13 @@ CONFIG = AppConfig().config
REDIS_HOST = os.environ.get("REDIS_HOST") REDIS_HOST = os.environ.get("REDIS_HOST")
REDIS_PORT = os.environ.get("REDIS_PORT") or 6379 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 = Celery("tasks", broker=f"redis://{REDIS_HOST}:{REDIS_PORT}")
app.config_from_object("django.conf:settings", namespace="ta:") app.config_from_object("django.conf:settings", namespace="ta:")
app.autodiscover_tasks() app.autodiscover_tasks()
@shared_task @shared_task(name="update_subscribed")
def update_subscribed(): def update_subscribed():
"""look for missing videos and add to pending""" """look for missing videos and add to pending"""
message = { message = {
@ -58,7 +58,7 @@ def update_subscribed():
check_reindex.delay() check_reindex.delay()
@shared_task @shared_task(name="download_pending")
def download_pending(): def download_pending():
"""download latest pending videos""" """download latest pending videos"""
have_lock = False have_lock = False
@ -120,7 +120,7 @@ def extrac_dl(youtube_ids):
thumb_handler.download_vid(all_videos_added) thumb_handler.download_vid(all_videos_added)
@shared_task @shared_task(name="check_reindex")
def check_reindex(): def check_reindex():
"""run the reindex main command""" """run the reindex main command"""
reindex_old_documents() reindex_old_documents()
@ -148,7 +148,7 @@ def run_manual_import():
my_lock.release() my_lock.release()
@shared_task @shared_task(name="run_backup")
def run_backup(): def run_backup():
"""called from settings page, dump backup to zip file""" """called from settings page, dump backup to zip file"""
backup_all_indexes() backup_all_indexes()
@ -193,6 +193,12 @@ def rescan_filesystem():
validate_thumbnails() validate_thumbnails()
@shared_task(name="thumbnail_check")
def thumbnail_check():
"""validate thumbnails"""
validate_thumbnails()
@shared_task @shared_task
def re_sync_thumbs(): def re_sync_thumbs():
"""sync thumbnails to mediafiles""" """sync thumbnails to mediafiles"""
@ -269,3 +275,6 @@ def index_channel_playlists(channel_id):
handler.download_playlist(missing_playlists) handler.download_playlist(missing_playlists)
return return
app.conf.beat_schedule = ScheduleBuilder().build_schedule()