Commit 4f211c08 authored by echel0n's avatar echel0n

Refactored web handler for getting manual search statuses

parent 31e16d29
......@@ -42,7 +42,6 @@ class SearchQueue(Queue):
def __init__(self):
Queue.__init__(self, "SEARCHQUEUE")
self.SNATCH_HISTORY = deque(maxlen=100)
self.MANUAL_SEARCH_HISTORY = deque(maxlen=100)
def is_in_queue(self, show_id, season, episode):
for task in self.tasks.copy().values():
......@@ -59,7 +58,7 @@ class SearchQueue(Queue):
return False
def is_show_in_queue(self, show_id):
return any(isinstance(task, (ManualSearchTask, FailedSearchTask)) and task.show_id == show_id for task in self.tasks.copy().values())
return any(self.get_all_tasks_from_queue_by_show(show_id))
def get_all_tasks_from_queue_by_show(self, show_id):
return [task for task in self.tasks.copy().values() if task.show_id == show_id]
......@@ -133,8 +132,8 @@ class DailySearchTask(Task):
self.show_id = show_id
self.season = season
self.episode = episode
self.success = False
self.started = False
self.success = False
def run(self):
self.started = True
......@@ -172,8 +171,8 @@ class ManualSearchTask(Task):
self.show_id = show_id
self.season = season
self.episode = episode
self.success = False
self.started = False
self.success = False
self.priority = TaskPriority.EXTREME
self.downCurQuality = downCurQuality
self.auto_remove = False
......@@ -208,7 +207,6 @@ class ManualSearchTask(Task):
sickrage.app.log.debug(traceback.format_exc())
finally:
sickrage.app.log.info("Finished manual search for: [" + episode_object.pretty_name() + "]")
sickrage.app.search_queue.MANUAL_SEARCH_HISTORY.append(self)
class BacklogSearchTask(Task):
......@@ -219,8 +217,8 @@ class BacklogSearchTask(Task):
self.season = season
self.episode = episode
self.priority = TaskPriority.LOW
self.success = False
self.started = False
self.success = False
def run(self):
self.started = True
......@@ -260,8 +258,8 @@ class FailedSearchTask(Task):
self.episode = episode
self.priority = TaskPriority.HIGH
self.downCurQuality = downCurQuality
self.success = False
self.started = False
self.success = False
self.auto_remove = False
def run(self):
......@@ -301,5 +299,4 @@ class FailedSearchTask(Task):
except Exception:
sickrage.app.log.debug(traceback.format_exc())
finally:
sickrage.app.log.info("Finished failed download search for: [" + show_object.name + "]")
sickrage.app.search_queue.MANUAL_SEARCH_HISTORY.append(self)
sickrage.app.log.info("Finished failed download search for: [" + show_object.name + "]")
\ No newline at end of file
......@@ -46,6 +46,7 @@ from sickrage.core.exceptions import (
from sickrage.core.helpers import clean_url, clean_host, clean_hosts, get_disk_space_usage
from sickrage.core.helpers.anidb import get_release_groups_for_anime
from sickrage.core.helpers.srdatetime import SRDateTime
from sickrage.core.queues import TaskStatus
from sickrage.core.queues.search import FailedSearchTask, ManualSearchTask
from sickrage.core.scene_numbering import (
get_scene_numbering_for_show,
......@@ -1511,32 +1512,18 @@ class GetManualSearchStatusHandler(BaseHandler, ABC):
episodes = []
# Queued Manual Searches
for search_task in sickrage.app.search_queue.get_all_tasks_from_queue_by_show(show):
for search_task in sickrage.app.search_queue.get_all_tasks_from_queue_by_show(int(show)):
if isinstance(search_task, (ManualSearchTask, FailedSearchTask)):
episodes += self.get_episodes(int(show), [search_task], 'Queued')
# Running Manual Searches
if sickrage.app.search_queue.is_manual_search_in_progress():
for search_task in sickrage.app.search_queue.tasks.copy().values():
if isinstance(search_task, (ManualSearchTask, FailedSearchTask)) and not search_task.success:
if search_task.status == TaskStatus.QUEUED:
# Queued Manual Searches
episodes += self.get_episodes(int(show), [search_task], 'Queued')
elif search_task.status == TaskStatus.STARTED:
# Running Manual Searches
episodes += self.get_episodes(int(show), [search_task], 'Searching')
# Finished Manual Searches
for search_task in sickrage.app.search_queue.MANUAL_SEARCH_HISTORY.copy():
if show is not None:
if not str(search_task.show_id) == show:
continue
if isinstance(search_task, (ManualSearchTask, FailedSearchTask)):
if not [x for x in episodes if x['season'] == search_task.season and x['episode'] == search_task.episode]:
episodes += self.get_episodes(int(show), [search_task], 'Finished')
else:
# These are only Failed Downloads/Retry SearchThreadItems.. lets loop through the episodes
if not [i for i, j in zip(search_task, episodes) if i.season == j['season'] and i.episode == j['episode']]:
elif search_task.status == TaskStatus.FINISHED:
# Finished Manual Searches
episodes += self.get_episodes(int(show), [search_task], 'Finished')
sickrage.app.search_queue.remove_task(search_task.id)
sickrage.app.search_queue.remove_task(search_task.id)
return self.write(json_encode({'episodes': episodes}))
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment