Commit 753625db authored by echel0n's avatar echel0n

Refactored queue current item property to always represent current running task.

parent d599f2b7
# Changelog
- * 1589213 - 2018-11-11: Release v9.4.30
- * e191b1e - 2018-11-12: Refactored queue current item property to always represent current running task.
- * 8bd128e - 2018-11-11: Release v9.4.30
- * 90fdbb1 - 2018-11-11: Pre-Release v9.4.30.dev1
- * 007df0a - 2018-11-11: Refactored get, all, and get_many database functions.
- * f87d6ad - 2018-11-11: Release v9.4.29
......
......@@ -346,7 +346,7 @@ class srDatabase(object):
def all(self, *args, **kwargs):
with_doc = kwargs.pop('with_doc', True)
for data in self.db.all(*args, **kwargs):
if with_doc:
if with_doc :
try:
doc = self.db.get('id', data['_id'])
yield doc
......
......@@ -45,7 +45,7 @@ class srQueue(threading.Thread):
self.daemon = True
self._queue = PriorityQueue()
self._result_queue = Queue()
self.currentItem = None
self._current_items = []
self.min_priority = srQueuePriorities.EXTREME
self.amActive = False
self.lock = threading.Lock()
......@@ -61,20 +61,18 @@ class srQueue(threading.Thread):
self.amActive = True
if not self.is_paused:
if self.currentItem:
if self.next_item_priority < self.currentItem.priority:
__ = self.currentItem
self.currentItem = self.get()
self.currentItem.start()
self.currentItem.join()
self.currentItem = __
if self.current_item:
if self.next_item_priority < self.current_item.priority:
self.current_item = self.get()
self.current_item.start()
self.current_item.join()
if not self.currentItem or not self.currentItem.isAlive():
if self.currentItem:
self.currentItem = None
if not self.current_item or not self.current_item.isAlive():
if self.current_item:
self.current_item = None
self.currentItem = self.get()
self.currentItem.start()
self.current_item = self.get()
self.current_item.start()
self.amActive = False
......@@ -93,6 +91,18 @@ class srQueue(threading.Thread):
return priority
@property
def current_item(self):
if len(self._current_items):
return self._current_items[0]
@current_item.setter
def current_item(self, value):
if value:
self._current_items.insert(0, value)
else:
del self._current_items[0]
def get(self, *args, **kwargs):
__, __, item = self._queue.get(*args, **kwargs)
return item
......
......@@ -53,7 +53,7 @@ class PostProcessorQueue(srQueue):
:param proc_type: processing type, auto/manual
:return: instance of PostProcessorItem or None
"""
for __, __, cur_item in self.queue + [(None, None, self.currentItem)]:
for __, __, cur_item in self.queue + [(None, None, self.current_item)]:
if isinstance(cur_item,
PostProcessorItem) and cur_item.dirName == dirName and cur_item.proc_type == proc_type:
return cur_item
......@@ -61,7 +61,7 @@ class PostProcessorQueue(srQueue):
@property
def is_in_progress(self):
for __, __, cur_item in self.queue + [(None, None, self.currentItem)]:
for __, __, cur_item in self.queue + [(None, None, self.current_item)]:
if isinstance(cur_item, PostProcessorItem):
return True
return False
......@@ -74,7 +74,7 @@ class PostProcessorQueue(srQueue):
"""
length = {'auto': 0, 'manual': 0}
for __, __, cur_item in self.queue + [(None, None, self.currentItem)]:
for __, __, cur_item in self.queue + [(None, None, self.current_item)]:
if isinstance(cur_item, PostProcessorItem):
if cur_item.proc_type == 'auto':
length['auto'] += 1
......@@ -116,7 +116,7 @@ class PostProcessorQueue(srQueue):
item = self.find_in_queue(dirName, proc_type)
if item:
if self.currentItem == item:
if self.current_item == item:
return logHelper("Directory {} is already being processed right now, please wait until it completes "
"before trying again".format(dirName))
......
......@@ -94,20 +94,20 @@ class SearchQueue(srQueue):
def is_manualsearch_in_progress(self):
# Only referenced in webviews.py, only current running manualsearch or failedsearch is needed!!
if isinstance(self.currentItem, (ManualSearchQueueItem, FailedQueueItem)):
if isinstance(self.current_item, (ManualSearchQueueItem, FailedQueueItem)):
return True
return False
def is_backlog_in_progress(self):
for __, __, cur_item in self.queue + [(None, None, self.currentItem)]:
for __, __, cur_item in self.queue + [(None, None, self.current_item)]:
if isinstance(cur_item, BacklogQueueItem):
return True
return False
def is_dailysearch_in_progress(self):
for __, __, cur_item in self.queue + [(None, None, self.currentItem)]:
for __, __, cur_item in self.queue + [(None, None, self.current_item)]:
if isinstance(cur_item, DailySearchQueueItem):
return True
......@@ -115,7 +115,7 @@ class SearchQueue(srQueue):
def queue_length(self):
length = {'backlog': 0, 'daily': 0, 'manual': 0, 'failed': 0}
for __, __, cur_item in self.queue + [(None, None, self.currentItem)]:
for __, __, cur_item in self.queue + [(None, None, self.current_item)]:
if isinstance(cur_item, DailySearchQueueItem):
length['daily'] += 1
elif isinstance(cur_item, BacklogQueueItem):
......
......@@ -43,6 +43,10 @@ class ShowQueue(srQueue):
def __init__(self):
srQueue.__init__(self, "SHOWQUEUE")
@property
def is_busy(self):
return bool(len(self._get_queue_items()))
@property
def loading_show_list(self):
return self._get_loading_show_list()
......@@ -52,7 +56,7 @@ class ShowQueue(srQueue):
x.action_id in actions] if show else False
def _is_being(self, show, actions):
return self.currentItem is not None and show == self.currentItem.show and self.currentItem.action_id in actions
return self.current_item is not None and show == self.current_item.show and self.current_item.action_id in actions
def is_in_update_queue(self, show):
return self._is_in_queue(show, (ShowQueueActions.UPDATE, ShowQueueActions.FORCEUPDATE))
......@@ -84,8 +88,11 @@ class ShowQueue(srQueue):
def is_being_subtitled(self, show):
return self._is_being(show, (ShowQueueActions.SUBTITLE,))
def _get_queue_items(self):
return [x for __, __, x in self.queue + [(None, None, self.current_item)] if x]
def _get_loading_show_list(self):
return [x for __, __, x in self.queue + [(None, None, self.currentItem)] if x and x.is_loading]
return [x for x in self._get_queue_items() if x.is_loading]
def updateShow(self, show, force=False):
if self.is_being_added(show):
......@@ -155,7 +162,7 @@ class ShowQueue(srQueue):
# remove other queued actions for this show.
for __, __, x in self.queue:
if x and x.show and x != self.currentItem and show.indexerid == x.show.indexerid:
if x and x.show and x != self.current_item and show.indexerid == x.show.indexerid:
self.queue.remove(x)
return self.put(QueueItemRemove(show=show, full=full))
......@@ -204,7 +211,7 @@ class ShowQueueItem(srQueueItem):
self.show.flushEpisodes()
def is_in_queue(self):
return self in sickrage.app.show_queue.queue + [sickrage.app.show_queue.currentItem]
return self in sickrage.app.show_queue.queue + [sickrage.app.show_queue.current_item]
@property
def show_name(self):
......
......@@ -172,7 +172,7 @@ class QueueProgressIndicator():
return len([x for x in self.queueItemList if x.is_in_queue()])
def nextName(self):
for curItem in [sickrage.app.show_queue.currentItem] + sickrage.app.show_queue.queue:
for curItem in [sickrage.app.show_queue.current_item] + sickrage.app.show_queue.queue:
if curItem in self.queueItemList:
return curItem.name
......
......@@ -73,36 +73,36 @@ class VersionUpdater(object):
self.amActive = False
def backup(self):
if self.safe_to_update():
# Do a system backup before update
sickrage.app.log.info("Config backup in progress...")
sickrage.app.alerts.message(_('Backup'), _('Config backup in progress...'))
try:
backupDir = os.path.join(sickrage.app.data_dir, 'backup')
if not os.path.isdir(backupDir):
os.mkdir(backupDir)
if backupSR(backupDir, keep_latest=True):
sickrage.app.log.info("Config backup successful, updating...")
sickrage.app.alerts.message(_('Backup'), _('Config backup successful, updating...'))
return True
else:
sickrage.app.log.warning("Config backup failed, aborting update")
sickrage.app.alerts.message(_('Backup'), _('Config backup failed, aborting update'))
return False
except Exception as e:
sickrage.app.log.warning('Update: Config backup failed. Error: {}'.format(e))
# Do a system backup before update
sickrage.app.log.info("Config backup in progress...")
sickrage.app.alerts.message(_('Backup'), _('Config backup in progress...'))
try:
backupDir = os.path.join(sickrage.app.data_dir, 'backup')
if not os.path.isdir(backupDir):
os.mkdir(backupDir)
if backupSR(backupDir, keep_latest=True):
sickrage.app.log.info("Config backup successful, updating...")
sickrage.app.alerts.message(_('Backup'), _('Config backup successful, updating...'))
return True
else:
sickrage.app.log.warning("Config backup failed, aborting update")
sickrage.app.alerts.message(_('Backup'), _('Config backup failed, aborting update'))
return False
except Exception as e:
sickrage.app.log.warning('Update: Config backup failed. Error: {}'.format(e))
sickrage.app.alerts.message(_('Backup'), _('Config backup failed, aborting update'))
return False
@staticmethod
def safe_to_update():
if not sickrage.app.started:
return True
if not sickrage.app.auto_postprocessor.amActive:
return True
if sickrage.app.show_queue.is_busy:
sickrage.app.log.debug("We can't proceed with updating, show queue is busy")
return False
sickrage.app.log.debug("We can't proceed with the update. Post-Processor is running")
if sickrage.app.auto_postprocessor.amActive:
sickrage.app.log.debug("We can't proceed with updating, post-processor is running")
return False
@staticmethod
def find_install_type():
......@@ -145,20 +145,31 @@ class VersionUpdater(object):
return True
def update(self):
if self.updater and self.backup():
if self.updater:
# check if its safe to update
if not self.safe_to_update():
return False
# backup
if not self.backup():
return False
# check for updates
if self.updater.need_update():
if self.updater.update():
# Clean up after update
to_clean = os.path.join(sickrage.app.cache_dir, 'mako')
if not self.updater.need_update():
return False
for root, dirs, files in os.walk(to_clean, topdown=False):
[os.remove(os.path.join(root, name)) for name in files]
[shutil.rmtree(os.path.join(root, name)) for name in dirs]
# attempt update
if self.updater.update():
# Clean up after update
to_clean = os.path.join(sickrage.app.cache_dir, 'mako')
sickrage.app.config.view_changelog = True
for root, dirs, files in os.walk(to_clean, topdown=False):
[os.remove(os.path.join(root, name)) for name in files]
[shutil.rmtree(os.path.join(root, name)) for name in dirs]
return True
sickrage.app.config.view_changelog = True
return True
@property
def version(self):
......
......@@ -2031,7 +2031,7 @@ class Home(WebHandler):
# Running Searches
searchstatus = 'searching'
if sickrage.app.search_queue.is_manualsearch_in_progress():
searchThread = sickrage.app.search_queue.currentItem
searchThread = sickrage.app.search_queue.current_item
if searchThread.success:
searchstatus = 'finished'
......
......@@ -122,36 +122,36 @@
</tr>
</thead>
<tbody>
% if sickrage.app.show_queue.currentItem is not None:
% if sickrage.app.show_queue.current_item is not None:
<tr>
% try:
<% showindexerid = sickrage.app.show_queue.currentItem.show.indexerid %>
<% showindexerid = sickrage.app.show_queue.current_item.show.indexerid %>
<td>${showindexerid}</td>
% except Exception:
<td></td>
% endtry
% try:
<% showname = sickrage.app.show_queue.currentItem.show.name %>
<% showname = sickrage.app.show_queue.current_item.show.name %>
<td>${showname}</td>
% except Exception:
% if sickrage.app.show_queue.currentItem.action_id == ShowQueueActions.ADD:
<td>${sickrage.app.show_queue.currentItem.showDir}</td>
% if sickrage.app.show_queue.current_item.action_id == ShowQueueActions.ADD:
<td>${sickrage.app.show_queue.current_item.showDir}</td>
% else:
<td></td>
% endif
% endtry
<td>${sickrage.app.show_queue.currentItem.is_alive()}</td>
% if sickrage.app.show_queue.currentItem.priority == 10:
<td>${sickrage.app.show_queue.current_item.is_alive()}</td>
% if sickrage.app.show_queue.current_item.priority == 10:
<td>${_('LOW')}</td>
% elif sickrage.app.show_queue.currentItem.priority == 20:
% elif sickrage.app.show_queue.current_item.priority == 20:
<td>${_('NORMAL')}</td>
% elif sickrage.app.show_queue.currentItem.priority == 30:
% elif sickrage.app.show_queue.current_item.priority == 30:
<td>${_('HIGH')}</td>
% else:
<td>${sickrage.app.show_queue.currentItem.priority}</td>
<td>${sickrage.app.show_queue.current_item.priority}</td>
% endif
<td>${sickrage.app.show_queue.currentItem.added.strftime(dateTimeFormat)}</td>
<td>${ShowQueueActions.names[sickrage.app.show_queue.currentItem.action_id]}</td>
<td>${sickrage.app.show_queue.current_item.added.strftime(dateTimeFormat)}</td>
<td>${ShowQueueActions.names[sickrage.app.show_queue.current_item.action_id]}</td>
</tr>
% endif
% for __, __, item in sickrage.app.show_queue.queue:
......
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