diff --git a/tubesync/sync/youtube.py b/tubesync/sync/youtube.py index 665ec67a..3ea3c333 100644 --- a/tubesync/sync/youtube.py +++ b/tubesync/sync/youtube.py @@ -245,9 +245,9 @@ def download_media( 'writethumbnail': True, 'check_formats': False, 'overwrites': None, - 'sleep_interval': 30, - 'max_sleep_interval': 600, - 'sleep_interval_requests': 30, + 'sleep_interval': 10 + int(settings.DOWNLOAD_MEDIA_DELAY / 20), + 'max_sleep_interval': settings.DOWNLOAD_MEDIA_DELAY, + 'sleep_interval_requests': 5, 'paths': opts.get('paths', dict()), 'postprocessor_args': opts.get('postprocessor_args', dict()), 'postprocessor_hooks': opts.get('postprocessor_hooks', list()), diff --git a/tubesync/tubesync/local_settings.py.container b/tubesync/tubesync/local_settings.py.container index 87ee3aa4..9d975ac6 100644 --- a/tubesync/tubesync/local_settings.py.container +++ b/tubesync/tubesync/local_settings.py.container @@ -52,10 +52,7 @@ else: DEFAULT_THREADS = 1 -MAX_BACKGROUND_TASK_ASYNC_THREADS = 8 BACKGROUND_TASK_ASYNC_THREADS = int(os.getenv('TUBESYNC_WORKERS', DEFAULT_THREADS)) -if BACKGROUND_TASK_ASYNC_THREADS > MAX_BACKGROUND_TASK_ASYNC_THREADS: - BACKGROUND_TASK_ASYNC_THREADS = MAX_BACKGROUND_TASK_ASYNC_THREADS MEDIA_ROOT = CONFIG_BASE_DIR / 'media' diff --git a/tubesync/tubesync/settings.py b/tubesync/tubesync/settings.py index 3c350ab3..20b53fcc 100644 --- a/tubesync/tubesync/settings.py +++ b/tubesync/tubesync/settings.py @@ -181,6 +181,13 @@ RENAME_SOURCES = None +# WARNING WARNING WARNING +# Below this line, the logic and formulas must remain as they are. +# Changing them is very likely to break the software in weird ways. +# To change anything, you should adjust a variable above or in the +# 'local_settings.py' file instead. +# You have been warned! + try: from .local_settings import * except ImportError as e: @@ -189,5 +196,22 @@ sys.exit(1) +try: + MAX_RUN_TIME = int(str(MAX_RUN_TIME), base=10) +except: + # fall back to the default value from: + # https://github.com/django-background-tasks/django-background-tasks/blob/12c8f328e4ba704bd7d91534bb6569e70197b949/background_task/settings.py#L28 + MAX_RUN_TIME = 3600 + +# Tasks scheduled with `background_task` need a chance to finish +if MAX_RUN_TIME < 600: + MAX_RUN_TIME = 600 + +DOWNLOAD_MEDIA_DELAY = 60 + (MAX_RUN_TIME / 20) + +if BACKGROUND_TASK_ASYNC_THREADS > MAX_BACKGROUND_TASK_ASYNC_THREADS: + BACKGROUND_TASK_ASYNC_THREADS = MAX_BACKGROUND_TASK_ASYNC_THREADS + + from .dbutils import patch_ensure_connection patch_ensure_connection()