Merge pull request #672 from tcely/patch-3

Adjustments for downloading delays
This commit is contained in:
meeb 2025-02-02 16:46:23 +11:00 committed by GitHub
commit 4902a446b4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 27 additions and 6 deletions

View File

@ -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()),

View File

@ -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'

View File

@ -181,6 +181,13 @@ RENAME_ALL_SOURCES = False
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 @@ except ImportError as e:
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()