diff --git a/config/root/etc/services.d/celery-beat/run b/config/root/etc/services.d/celery-beat/run new file mode 100755 index 0000000..46b03a6 --- /dev/null +++ b/config/root/etc/services.d/celery-beat/run @@ -0,0 +1,25 @@ +#!/usr/bin/with-contenv bash + +UMASK_SET=${UMASK_SET:-022} +umask "$UMASK_SET" + +cd /app || exit + +PIDFILE=/run/app/celery-beat.pid +SCHEDULE=/tmp/tubesync-celerybeat-schedule + +if [ -f "${PIDFILE}" ] +then + PID=$(cat $PIDFILE) + echo "Unexpected PID file exists at ${PIDFILE} with PID: ${PID}" + if kill -0 $PID + then + echo "Killing old gunicorn process with PID: ${PID}" + kill -9 $PID + fi + echo "Removing stale PID file: ${PIDFILE}" + rm ${PIDFILE} +fi + +#exec s6-setuidgid app \ +# /usr/local/bin/celery --workdir /app -A tubesync beat --pidfile ${PIDFILE} -s ${SCHEDULE} diff --git a/config/root/etc/services.d/celery-worker/run b/config/root/etc/services.d/celery-worker/run new file mode 100755 index 0000000..04e2a32 --- /dev/null +++ b/config/root/etc/services.d/celery-worker/run @@ -0,0 +1,24 @@ +#!/usr/bin/with-contenv bash + +UMASK_SET=${UMASK_SET:-022} +umask "$UMASK_SET" + +cd /app || exit + +PIDFILE=/run/app/celery-worker.pid + +if [ -f "${PIDFILE}" ] +then + PID=$(cat $PIDFILE) + echo "Unexpected PID file exists at ${PIDFILE} with PID: ${PID}" + if kill -0 $PID + then + echo "Killing old gunicorn process with PID: ${PID}" + kill -9 $PID + fi + echo "Removing stale PID file: ${PIDFILE}" + rm ${PIDFILE} +fi + +#exec s6-setuidgid app \ +# /usr/local/bin/celery --workdir /app -A tubesync worker --pidfile ${PIDFILE} -l INFO diff --git a/tubesync/tubesync/celery.py b/tubesync/tubesync/celery.py new file mode 100644 index 0000000..aad3092 --- /dev/null +++ b/tubesync/tubesync/celery.py @@ -0,0 +1,19 @@ +import os +from celery import Celery + + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'tubesync.settings') +REDIS_CONNECTION = os.getenv('REDIS_CONNECTION', 'redis://localhost:6379/0') + + +app = Celery('tubesync') +app.config_from_object('django.conf:settings', namespace='CELERY') +app.autodiscover_tasks() +app.conf.broker_url = REDIS_CONNECTION +app.conf.beat_schedule = { + '10-second-beat': { + 'task': 'sync.tasks.housekeeping_task', + 'schedule': 60.0, + 'args': () + }, +} diff --git a/tubesync/tubesync/local_settings.py.container b/tubesync/tubesync/local_settings.py.container index a105058..b86d04d 100644 --- a/tubesync/tubesync/local_settings.py.container +++ b/tubesync/tubesync/local_settings.py.container @@ -64,6 +64,7 @@ if BACKGROUND_TASK_ASYNC_THREADS > MAX_BACKGROUND_TASK_ASYNC_THREADS: MEDIA_ROOT = CONFIG_BASE_DIR / 'media' DOWNLOAD_ROOT = DOWNLOADS_BASE_DIR YOUTUBE_DL_CACHEDIR = CONFIG_BASE_DIR / 'cache' +COOKIES_FILE = CONFIG_BASE_DIR / 'cookies.txt' BASICAUTH_USERNAME = os.getenv('HTTP_USER', '').strip()