Not sending refresh events for channel downloads.

This commit is contained in:
Roland 2022-12-29 09:36:24 -07:00
parent 6122ebb68c
commit 9dfaabdb9b
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
5 changed files with 15 additions and 9 deletions

View file

@ -255,7 +255,8 @@ def test_channel_empty_url_doesnt_conflict(test_client, test_session, test_direc
@pytest.mark.asyncio
async def test_download_channel_no_refresh(test_session, download_channel, video_download_manager, video_factory):
async def test_channel_download_requires_refresh(test_session, download_channel, video_download_manager, video_factory,
events_history):
"""A Channel cannot be downloaded until it has been refreshed.
Videos already downloaded are not downloaded again."""
@ -301,6 +302,9 @@ async def test_download_channel_no_refresh(test_session, download_channel, video
# Only the missing video was downloaded.
assert downloaded_urls == ['https://example.com/2']
# Should not send refresh events because downloads are automated.
assert events_history == []
def test_channel_post_directory(test_session, test_client, test_directory):
"""A Channel can be created with or without an existing directory."""

View file

@ -137,7 +137,7 @@ class ChannelDownloader(Downloader, ABC):
channel = get_channel(session, channel_id=channel_id, return_dict=False)
if not channel.videos or not channel.refreshed:
logger.warning(f'Refreshing videos in {channel.directory} because {channel} has no video records!')
await channel.refresh_files()
await channel.refresh_files(send_events=False)
session.commit() # Commit the refresh.
session.refresh(channel)

View file

@ -479,14 +479,14 @@ class Channel(ModelHelper, Base):
)
return statistics
async def refresh_files(self):
async def refresh_files(self, send_events: bool = True):
"""Refresh all files within this Channel's directory. Mark this channel as refreshed."""
logger.debug('Channel.refresh_files refresh_files')
# Get this Channel's ID for later. Refresh may take a long time.
self_id = self.id
# Refresh all files within this channel's directory first.
await refresh_directory_files_recursively(self.directory)
await refresh_directory_files_recursively(self.directory, send_events=send_events)
# Apply any info_json (discover censored videos, etc.) second.
from modules.videos.common import apply_info_json

View file

@ -321,7 +321,8 @@ def mock_create_subprocess_shell():
def events_history():
"""Give each test it's own Events history."""
with mock.patch('wrolpi.events.EVENTS_HISTORY', list()):
yield
from wrolpi.events import EVENTS_HISTORY
yield EVENTS_HISTORY
FLAGS_LOCK = multiprocessing.Lock()

View file

@ -22,7 +22,6 @@ from wrolpi.db import get_db_session, get_db_curs, get_ranked_models
from wrolpi.errors import InvalidFile
from wrolpi.events import Events
from wrolpi.files.models import File
from wrolpi import flags
from wrolpi.vars import PYTEST, FILE_REFRESH_CHUNK_SIZE
try:
@ -359,7 +358,7 @@ async def refresh_files():
@limit_concurrent(1)
@wrol_mode_check
@cancelable_wrapper
async def refresh_directory_files_recursively(directory: Union[pathlib.Path, str]):
async def refresh_directory_files_recursively(directory: Union[pathlib.Path, str], send_events: bool = True):
"""Upsert and index all files within a directory (recursively).
Any records of the files that are no longer in the directory will be removed."""
@ -369,7 +368,8 @@ async def refresh_directory_files_recursively(directory: Union[pathlib.Path, str
raise ValueError(f'Cannot refresh files of a file: {directory=}')
relative_path = str(get_relative_to_media_directory(directory))
Events.send_directory_refresh_started(f'Refresh of {repr(relative_path)} has started.')
if send_events:
Events.send_directory_refresh_started(f'Refresh of {repr(relative_path)} has started.')
# All Files older than this will be removed.
idempotency = now()
@ -395,7 +395,8 @@ async def refresh_directory_files_recursively(directory: Union[pathlib.Path, str
apply_after_refresh()
await apply_indexers()
Events.send_directory_refresh_completed(f'Refresh of {repr(relative_path)} has completed.')
if send_events:
Events.send_directory_refresh_completed(f'Refresh of {repr(relative_path)} has completed.')
refresh_logger.info(f'Done refreshing files in {directory}')