Skip to content

Commit

Permalink
Fixing starting downloads on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
lrnselfreliance committed Dec 26, 2024
1 parent 54aa191 commit 08a67ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
14 changes: 10 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
create_empty_config_files, TRACE_LEVEL
from wrolpi.contexts import attach_shared_contexts, reset_shared_contexts, initialize_configs_contexts
from wrolpi.dates import Seconds
from wrolpi.downloader import import_downloads_config, download_manager
from wrolpi.downloader import import_downloads_config, download_manager, get_download_manager_config
from wrolpi.errors import WROLModeEnabled
from wrolpi.vars import PROJECT_DIR, DOCKERIZED, INTERNET_SERVER
from wrolpi.version import get_version_string
Expand Down Expand Up @@ -257,9 +257,6 @@ async def start_single_tasks(app: Sanic):
# Set all downloads to new.
download_manager.retry_downloads()

if get_wrolpi_config().download_on_startup and download_manager.can_download:
await download_manager.enable()

# Hotspot/throttle are not supported in Docker containers.
if not DOCKERIZED:
if get_wrolpi_config().hotspot_on_startup:
Expand All @@ -280,6 +277,15 @@ async def start_single_tasks(app: Sanic):
else:
logger.info('CPU throttle on startup is disabled')

if get_wrolpi_config().download_on_startup and not wrol_mode_enabled():
# Only start downloading when prerequisites have been met.
try:
async with flags.have_internet.wait_for(timeout=30):
if get_download_manager_config().successful_import:
await download_manager.enable()
except TimeoutError as e:
logger.error('Failed to enable download', exc_info=e)

logger.debug(f'start_single_tasks done')


Expand Down
7 changes: 4 additions & 3 deletions modules/videos/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
escape_file_name, get_media_directory, background_task, Base, get_wrolpi_config
from wrolpi.dates import Seconds, from_timestamp
from wrolpi.db import get_db_curs, get_db_session
from wrolpi.downloader import Download
from wrolpi.downloader import Download, download_manager
from wrolpi.errors import UnknownDirectory
from wrolpi.events import Events
from wrolpi.files.lib import split_path_stem_and_suffix
Expand Down Expand Up @@ -297,8 +297,9 @@ def import_config(self, file: pathlib.Path = None, send_events=False):

if not channel.source_id and channel.url and flags.have_internet.is_set():
# If we can download from a channel, we must have its source_id.
logger.info(f'Fetching channel source id for {channel}')
background_task(fetch_channel_source_id(channel.id))
if download_manager.can_download:
logger.info(f'Fetching channel source id for {channel}')
background_task(fetch_channel_source_id(channel.id))

channel_import_logger.debug(f'Updated {repr(channel.name)}'
f' url={channel.url}'
Expand Down

0 comments on commit 08a67ea

Please sign in to comment.