From f830fe3dcca2c3ea5c18cacacfd22528fb6fd339 Mon Sep 17 00:00:00 2001 From: Roland Date: Mon, 27 Dec 2021 16:43:52 -0700 Subject: [PATCH] Dropping channel.next_download. Removing noisy download logs. --- ...84b6993a6091_drop_channel_next_download.py | 31 +++++++++++++++++++ main.py | 2 +- modules/videos/channel/lib.py | 8 +++-- wrolpi/downloader.py | 8 ++--- 4 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 alembic/versions/84b6993a6091_drop_channel_next_download.py diff --git a/alembic/versions/84b6993a6091_drop_channel_next_download.py b/alembic/versions/84b6993a6091_drop_channel_next_download.py new file mode 100644 index 00000000..77b4c215 --- /dev/null +++ b/alembic/versions/84b6993a6091_drop_channel_next_download.py @@ -0,0 +1,31 @@ +"""Drop channel next_download + +Revision ID: 84b6993a6091 +Revises: 8df411232c17 +Create Date: 2021-12-27 16:42:32.099796 + +""" +import os +from alembic import op +from sqlalchemy.orm import Session + + +# revision identifiers, used by Alembic. +revision = '84b6993a6091' +down_revision = '8df411232c17' +branch_labels = None +depends_on = None + +DOCKERIZED = True if os.environ.get('DOCKER', '').lower().startswith('t') else False + + +def upgrade(): + bind = op.get_bind() + session = Session(bind=bind) + session.execute('ALTER TABLE channel DROP COLUMN IF EXISTS next_download') + + +def downgrade(): + bind = op.get_bind() + session = Session(bind=bind) + session.execute('ALTER TABLE channel ADD COLUMN IF NOT EXISTS next_download DATE') diff --git a/main.py b/main.py index 73b70d6c..2997e92b 100755 --- a/main.py +++ b/main.py @@ -113,6 +113,7 @@ def periodic_downloads(app: Sanic, loop): if wrol_mode_enabled(): logger.warning(f'Not starting download worker because WROL Mode is enabled.') return + logger.info('Starting download manager.') # Set all downloads to new. download_manager.reset_downloads() @@ -122,7 +123,6 @@ def periodic_downloads(app: Sanic, loop): download_manager.delete_old_once_downloads() await download_manager.do_downloads() seconds = 60 - logger.debug(f'Waiting {seconds} seconds to start next download') await asyncio.sleep(seconds) app.add_task(_periodic_download()) diff --git a/modules/videos/channel/lib.py b/modules/videos/channel/lib.py index a88eabcd..f9b6c234 100644 --- a/modules/videos/channel/lib.py +++ b/modules/videos/channel/lib.py @@ -67,16 +67,18 @@ async def get_channels_video_count() -> Dict[int, int]: return video_counts -def get_channel(source_id: str = None, link: str = None, url: str = None, return_dict: bool = True - ) -> Union[dict, Channel]: +COD = Union[dict, Channel] + + +def get_channel(source_id: str = None, link: str = None, url: str = None, return_dict: bool = True) -> COD: """ Attempt to find a Channel using the provided params. The params are in order of reliability. Raises UnknownChannel if no channel is found. """ with get_db_session() as session: + channel: COD = None # noqa # Try by source_id first. - channel = None if source_id: channel = session.query(Channel).filter_by(source_id=source_id).one_or_none() if not channel and link: diff --git a/wrolpi/downloader.py b/wrolpi/downloader.py index 58e26168..9bab06b6 100644 --- a/wrolpi/downloader.py +++ b/wrolpi/downloader.py @@ -312,11 +312,6 @@ class DownloadManager: try: downloads = self.get_new_downloads(session) - if not downloads: - logger.info('No new downloads') - return - - logger.info(f'Doing downloads.') download_count = 0 for download in downloads: download_count += 1 @@ -350,7 +345,8 @@ class DownloadManager: download.defer() session_.commit() - logger.info(f'Done doing {download_count} downloads.') + if download_count: + logger.info(f'Done doing {download_count} downloads.') finally: session.close()