mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-30 11:56:18 -05:00
Fixing upsert_file usage. Adding log details for error.
This commit is contained in:
parent
eb017d21e7
commit
77ad52473a
5 changed files with 13 additions and 11 deletions
|
|
@ -137,11 +137,11 @@ class ChannelDownloader(Downloader, ABC):
|
|||
downloads=downloads,
|
||||
settings=settings,
|
||||
)
|
||||
except Exception:
|
||||
except Exception as e:
|
||||
if PYTEST:
|
||||
raise
|
||||
kind = 'playlist' if is_a_playlist else 'channel'
|
||||
logger.warning(f'Failed to update catalog of {kind} {download.url}')
|
||||
logger.error(f'Failed to update catalog of {kind} {download.url}', exc_info=e)
|
||||
return DownloadResult(
|
||||
success=False,
|
||||
location=location,
|
||||
|
|
|
|||
|
|
@ -436,8 +436,7 @@ class Video(ModelHelper, Base):
|
|||
def delete_video(video_: Video):
|
||||
"""Delete a Video with any of its tags."""
|
||||
for tag_name_ in video_.file_group.tag_names:
|
||||
tag_ = Tag.get_by_name(tag_name_)
|
||||
video_.file_group.untag(tag_, session)
|
||||
video_.file_group.untag(tag_name_, session)
|
||||
video_.delete()
|
||||
|
||||
changes = False
|
||||
|
|
|
|||
|
|
@ -245,8 +245,7 @@ class Download(ModelHelper, Base): # noqa
|
|||
def get_all_by_destination(cls, destination: str | pathlib.Path, session: Session = None) -> List['Download']:
|
||||
destination = str(destination)
|
||||
downloads = session.query(Download) \
|
||||
.filter(Download.settings.contains({'destination': destination})) \
|
||||
.all()
|
||||
.filter(Download.settings.contains({'destination': destination})).all() # noqa
|
||||
return downloads
|
||||
|
||||
|
||||
|
|
@ -595,7 +594,7 @@ class DownloadManager:
|
|||
).order_by(
|
||||
Download.frequency.is_(None),
|
||||
Download.frequency,
|
||||
Download.id)) # noqa
|
||||
Download.id))
|
||||
count = 0
|
||||
for download in new_downloads:
|
||||
domain = download.domain
|
||||
|
|
@ -727,7 +726,7 @@ class DownloadManager:
|
|||
for download in recurring:
|
||||
# A new download may not have a `next_download`, create it if necessary.
|
||||
download.next_download = download.next_download or self.calculate_next_download(download, session=session)
|
||||
if download.next_download < now_:
|
||||
if download.next_download < now_ and download.status not in (DownloadStatus.new, DownloadStatus.pending):
|
||||
download.renew()
|
||||
renewed_count += 1
|
||||
|
||||
|
|
@ -823,6 +822,7 @@ class DownloadManager:
|
|||
"""Delete all once-downloads that have expired.
|
||||
|
||||
Do not delete downloads that are new, or should be tried again."""
|
||||
count = 0
|
||||
with get_db_session(commit=True) as session:
|
||||
downloads = self.get_once_downloads(session)
|
||||
one_month = now() - timedelta(days=30)
|
||||
|
|
@ -830,6 +830,9 @@ class DownloadManager:
|
|||
if download.status in self.FINISHED_STATUSES and download.last_successful_download and \
|
||||
download.last_successful_download < one_month:
|
||||
session.delete(download)
|
||||
count += 1
|
||||
if count:
|
||||
self.log_debug(f'Deleted {count} once downloads')
|
||||
|
||||
def list_downloaders(self) -> List[Downloader]:
|
||||
"""Return a list of the Downloaders available on this Download Manager."""
|
||||
|
|
|
|||
|
|
@ -52,9 +52,8 @@ class FileDownloader(Downloader, ABC):
|
|||
try:
|
||||
await download_file(download.url, output_path, info)
|
||||
|
||||
with get_db_session(commit=True) as session:
|
||||
fg = await upsert_file(output_path, session=session, tag_names=download.settings.get('tag_names'))
|
||||
location = fg.location
|
||||
fg = await upsert_file(output_path, tag_names=download.settings.get('tag_names'))
|
||||
location = fg.location
|
||||
|
||||
return DownloadResult(
|
||||
success=True,
|
||||
|
|
|
|||
|
|
@ -1570,4 +1570,5 @@ async def upsert_file(file: pathlib.Path | str, tag_names: List[str] = None) ->
|
|||
file_group.add_tag(tag.id)
|
||||
|
||||
session.commit()
|
||||
file_group.flush()
|
||||
return file_group
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue