forked from platypush/platypush
Handle and log media workers search errors
This commit is contained in:
parent
f478e1ff40
commit
46d8d575ba
2 changed files with 28 additions and 5 deletions
|
@ -362,11 +362,18 @@ class MediaPlugin(Plugin, ABC):
|
|||
|
||||
for media_type in types:
|
||||
try:
|
||||
results[media_type].extend(
|
||||
results_queues[media_type].get(timeout=search_timeout))
|
||||
items = results_queues[media_type].get(timeout=search_timeout)
|
||||
if isinstance(items, Exception):
|
||||
raise items
|
||||
|
||||
results[media_type].extend(items)
|
||||
except queue.Empty:
|
||||
self.logger.warning('Search for "{}" media type {} timed out'.
|
||||
format(query, media_type))
|
||||
except Exception as e:
|
||||
self.logger.warning('Error while searching for "{}", media type {}'.
|
||||
format(query, media_type))
|
||||
self.logger.exception(e)
|
||||
|
||||
flattened_results = []
|
||||
|
||||
|
@ -391,7 +398,10 @@ class MediaPlugin(Plugin, ABC):
|
|||
@staticmethod
|
||||
def _search_worker(query, search_hndl, results_queue):
|
||||
def thread():
|
||||
try:
|
||||
results_queue.put(search_hndl.search(query))
|
||||
except Exception as e:
|
||||
results_queue.put(e)
|
||||
return thread
|
||||
|
||||
def _get_search_handler_by_type(self, search_type):
|
||||
|
|
|
@ -141,7 +141,11 @@ class TorrentPlugin(Plugin):
|
|||
def _torrent_search_worker(self, imdb_id: str, category: str, q: queue.Queue):
|
||||
base_url = self.torrent_base_urls.get(category)
|
||||
assert base_url, f'No such category: {category}'
|
||||
q.put(requests.get(base_url.format(imdb_id)).json())
|
||||
try:
|
||||
results = requests.get(base_url.format(imdb_id)).json()
|
||||
q.put(results)
|
||||
except Exception as e:
|
||||
q.put(e)
|
||||
|
||||
def _search_torrents(self, query, category):
|
||||
imdb_results = self._imdb_query(query, category)
|
||||
|
@ -156,13 +160,22 @@ class TorrentPlugin(Plugin):
|
|||
]
|
||||
|
||||
results = []
|
||||
errors = []
|
||||
|
||||
for worker in workers:
|
||||
worker.start()
|
||||
for q in result_queues:
|
||||
results.append(q.get())
|
||||
res_ = q.get()
|
||||
if isinstance(res_, Exception):
|
||||
errors.append(res_)
|
||||
else:
|
||||
results.append(res_)
|
||||
for worker in workers:
|
||||
worker.join()
|
||||
|
||||
if errors:
|
||||
self.logger.warning(f'Torrent search errors: {[str(e) for e in errors]}')
|
||||
|
||||
return results
|
||||
|
||||
@staticmethod
|
||||
|
|
Loading…
Reference in a new issue