2014-03-10 05:18:05 +00:00
|
|
|
# Author: Nic Wolfe <nic@wolfeden.ca>
|
|
|
|
# URL: http://code.google.com/p/sickbeard/
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# This file is part of SickGear.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is free software: you can redistribute it and/or modify
|
2014-03-10 05:18:05 +00:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
2014-11-12 16:43:14 +00:00
|
|
|
# SickGear is distributed in the hope that it will be useful,
|
2014-03-10 05:18:05 +00:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2014-05-26 20:16:07 +00:00
|
|
|
# GNU General Public License for more details.
|
2014-03-10 05:18:05 +00:00
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2014-11-12 16:43:14 +00:00
|
|
|
# along with SickGear. If not, see <http://www.gnu.org/licenses/>.
|
2014-03-10 05:18:05 +00:00
|
|
|
|
|
|
|
import datetime
|
|
|
|
import time
|
|
|
|
import threading
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
from sickbeard import logger
|
|
|
|
from sickbeard.exceptions import ex
|
|
|
|
|
|
|
|
|
2014-07-15 02:00:53 +00:00
|
|
|
class Scheduler(threading.Thread):
|
2014-06-19 07:12:30 +00:00
|
|
|
def __init__(self, action, cycleTime=datetime.timedelta(minutes=10), run_delay=datetime.timedelta(minutes=0),
|
2017-12-27 17:54:19 +00:00
|
|
|
start_time=None, threadName="ScheduledThread", silent=True, prevent_cycle_run=None, paused=False):
|
2014-07-15 02:00:53 +00:00
|
|
|
super(Scheduler, self).__init__()
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-06-19 07:12:30 +00:00
|
|
|
self.lastRun = datetime.datetime.now() + run_delay - cycleTime
|
2014-03-10 05:18:05 +00:00
|
|
|
self.action = action
|
|
|
|
self.cycleTime = cycleTime
|
2014-06-19 07:12:30 +00:00
|
|
|
self.start_time = start_time
|
2015-04-05 18:12:15 +00:00
|
|
|
self.prevent_cycle_run = prevent_cycle_run
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2014-07-15 02:00:53 +00:00
|
|
|
self.name = threadName
|
2014-03-10 05:18:05 +00:00
|
|
|
self.silent = silent
|
2017-12-27 17:54:19 +00:00
|
|
|
self._stop = threading.Event()
|
|
|
|
self._unpause = threading.Event()
|
|
|
|
if not paused:
|
|
|
|
self._unpause.set()
|
2017-11-02 10:29:16 +00:00
|
|
|
self.lock = threading.Lock()
|
2014-05-19 17:40:25 +00:00
|
|
|
self.force = False
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-12-27 17:54:19 +00:00
|
|
|
def pause(self):
|
|
|
|
self._unpause.clear()
|
|
|
|
|
|
|
|
def unpause(self):
|
|
|
|
self._unpause.set()
|
|
|
|
|
|
|
|
def stop(self):
|
|
|
|
self._stop.set()
|
|
|
|
self.unpause()
|
|
|
|
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
def set_paused_state(self):
|
|
|
|
if hasattr(self.action, 'is_enabled'):
|
|
|
|
self.silent = not self.action.is_enabled()
|
|
|
|
if self.silent:
|
2017-12-27 17:54:19 +00:00
|
|
|
self.pause()
|
|
|
|
else:
|
|
|
|
self.unpause()
|
|
|
|
|
2014-03-10 05:18:05 +00:00
|
|
|
def timeLeft(self):
|
|
|
|
return self.cycleTime - (datetime.datetime.now() - self.lastRun)
|
|
|
|
|
|
|
|
def forceRun(self):
|
|
|
|
if not self.action.amActive:
|
2014-05-19 17:40:25 +00:00
|
|
|
self.force = True
|
2014-03-10 05:18:05 +00:00
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2014-07-15 02:00:53 +00:00
|
|
|
def run(self):
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
self.set_paused_state()
|
2014-03-10 05:18:05 +00:00
|
|
|
|
2017-12-27 17:54:19 +00:00
|
|
|
# if self._unpause Event() is NOT set the loop pauses
|
|
|
|
while self._unpause.wait() and not self._stop.is_set():
|
2014-05-17 09:27:17 +00:00
|
|
|
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
if getattr(self.action, 'is_enabled', True):
|
|
|
|
try:
|
|
|
|
current_time = datetime.datetime.now()
|
|
|
|
should_run = False
|
2014-06-19 07:12:30 +00:00
|
|
|
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
# check if interval has passed
|
|
|
|
if current_time - self.lastRun >= self.cycleTime:
|
|
|
|
# check if wanting to start around certain time taking interval into account
|
|
|
|
if self.start_time:
|
|
|
|
hour_diff = current_time.time().hour - self.start_time.hour
|
|
|
|
if not hour_diff < 0 and hour_diff < self.cycleTime.seconds / 3600:
|
|
|
|
should_run = True
|
|
|
|
else:
|
|
|
|
# set lastRun to only check start_time after another cycleTime
|
|
|
|
self.lastRun = current_time
|
2015-05-04 19:14:29 +00:00
|
|
|
else:
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
should_run = True
|
2015-05-04 19:14:29 +00:00
|
|
|
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
if self.force:
|
|
|
|
should_run = True
|
2014-06-19 07:12:30 +00:00
|
|
|
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
if should_run and ((self.prevent_cycle_run is not None and self.prevent_cycle_run()) or
|
|
|
|
getattr(self.action, 'prevent_run', False)):
|
|
|
|
logger.log(u'%s skipping this cycleTime' % self.name, logger.WARNING)
|
|
|
|
# set lastRun to only check start_time after another cycleTime
|
|
|
|
self.lastRun = current_time
|
|
|
|
should_run = False
|
2015-04-05 18:12:15 +00:00
|
|
|
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
if should_run:
|
|
|
|
self.lastRun = current_time
|
2014-03-10 05:18:05 +00:00
|
|
|
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
try:
|
|
|
|
if not self.silent:
|
|
|
|
logger.log(u"Starting new thread: " + self.name, logger.DEBUG)
|
2014-05-08 14:03:50 +00:00
|
|
|
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
self.action.run()
|
|
|
|
except Exception as e:
|
|
|
|
logger.log(u"Exception generated in thread " + self.name + ": " + ex(e), logger.ERROR)
|
|
|
|
logger.log(repr(traceback.format_exc()), logger.ERROR)
|
2014-03-10 05:18:05 +00:00
|
|
|
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
finally:
|
|
|
|
if self.force:
|
|
|
|
self.force = False
|
|
|
|
else:
|
|
|
|
# disabled schedulers will only be rechecked every 30 seconds until enabled
|
|
|
|
time.sleep(30)
|
2014-05-19 17:40:25 +00:00
|
|
|
|
2014-07-15 02:00:53 +00:00
|
|
|
time.sleep(1)
|
|
|
|
|
|
|
|
# exiting thread
|
2017-12-27 17:54:19 +00:00
|
|
|
self._stop.clear()
|
Add choose to delete watched episodes from a list of played media at Kodi, Emby, and/or Plex.
Add episode watched state system that integrates with Kodi, Plex, and/or Emby, instructions at Shows/History/Layout/"Watched".
Add installable SickGear Kodi repository containing addon "SickGear Watched State Updater".
Change add Emby setting for watched state scheduler at Config/Notifications/Emby/"Update watched interval".
Change add Plex setting for watched state scheduler at Config/Notifications/Plex/"Update watched interval".
Add API cmd=sg.updatewatchedstate, instructions for use are linked to in layout "Watched" at /history.
Change history page table filter input values are saved across page refreshes.
Change history page table filter inputs, accept values like "dvd or web" to only display both.
Change history page table filter inputs, press 'ESC' key inside a filter input to reset it.
Add provider activity stats to Shows/History/Layout/ drop down.
Change move provider failures table from Manage/Media Search to Shows/History/Layout/Provider fails.
Change sort provider failures by most recent failure, and with paused providers at the top.
Change remove table form non-testing version 20007, that was reassigned.
2018-03-06 01:18:08 +00:00
|
|
|
self._unpause.clear()
|