From 6691c4948121aca500c2d2db78ffe01d6d1e9c24 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 19 Jan 2020 10:53:49 -0800 Subject: [PATCH] Add parameter skip_failures to refresh_all_channels. --- frontends/ycdl_flask/ycdl_flask/ycdl_flask.py | 3 ++- ycdl/ycdl.py | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/frontends/ycdl_flask/ycdl_flask/ycdl_flask.py b/frontends/ycdl_flask/ycdl_flask/ycdl_flask.py index 4449cda..e77697c 100644 --- a/frontends/ycdl_flask/ycdl_flask/ycdl_flask.py +++ b/frontends/ycdl_flask/ycdl_flask/ycdl_flask.py @@ -265,7 +265,8 @@ def refresher_thread(): while True: time.sleep(60 * 60 * 6) print('Starting refresh job.') - refresh_job = threading.Thread(target=youtube.refresh_all_channels, kwargs={'force': False}, daemon=True) + thread_kwargs = {'force': False, 'skip_failures': True} + refresh_job = threading.Thread(target=youtube.refresh_all_channels, kwargs=thread_kwargs, daemon=True) refresh_job.start() refresher = threading.Thread(target=refresher_thread, daemon=True) diff --git a/ycdl/ycdl.py b/ycdl/ycdl.py index 618fc35..fdf4d38 100644 --- a/ycdl/ycdl.py +++ b/ycdl/ycdl.py @@ -1,6 +1,7 @@ import logging import os import sqlite3 +import traceback from . import helpers from . import ytapi @@ -302,11 +303,20 @@ class YCDL: if commit: self.sql.commit() - def refresh_all_channels(self, force=False, commit=True): + def refresh_all_channels(self, force=False, skip_failures=False, commit=True): + exceptions = [] for channel in self.get_channels(): - self.refresh_channel(channel, force=force, commit=commit) + try: + self.refresh_channel(channel, force=force, commit=commit) + except Exception as exc: + if skip_failures: + traceback.print_exc() + exceptions.append(exc) + else: + raise if commit: self.sql.commit() + return exceptions def refresh_channel(self, channel, force=False, commit=True): if isinstance(channel, str):