diff options
Diffstat (limited to 'module/plugins/hooks/RestartFailed.py')
-rw-r--r-- | module/plugins/hooks/RestartFailed.py | 67 |
1 files changed, 27 insertions, 40 deletions
diff --git a/module/plugins/hooks/RestartFailed.py b/module/plugins/hooks/RestartFailed.py index 85553d738..07fb80967 100644 --- a/module/plugins/hooks/RestartFailed.py +++ b/module/plugins/hooks/RestartFailed.py @@ -1,57 +1,44 @@ # -*- coding: utf-8 -*- -""" - This program is free software; you can redistribute it and/or modify - 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. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. - See the GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see <http://www.gnu.org/licenses/>. - - @author: Walter Purcaro -""" - from module.plugins.Hook import Hook class RestartFailed(Hook): - __name__ = "RestartFailed" - __version__ = "1.53" + __name__ = "RestartFailed" + __type__ = "hook" + __version__ = "1.57" + + __config__ = [("interval", "int", "Check interval in minutes", 90)] + __description__ = """Periodically restart all failed downloads in queue""" - __config__ = [("activated", "bool", "Activated", False), - ("interval", "int", "Interval in minutes", 90)] - __author_name__ = "Walter Purcaro" - __author_mail__ = "vuolter@gmail.com" + __license__ = "GPLv3" + __authors__ = [("Walter Purcaro", "vuolter@gmail.com")] - event_list = ["pluginConfigChanged"] - MIN_INTERVAL = 15 * 60 # seconds + # event_list = ["pluginConfigChanged"] - def periodical(self): - self.logDebug("Restart all failed downloads now") - self.core.api.restartFailed() + MIN_INTERVAL = 15 * 60 #: 15m minimum check interval (value is in seconds) - def restartPeriodical(self, interval): - self.logDebug("Set periodical interval to %s seconds" % interval) - if self.cb: - self.core.scheduler.removeJob(self.cb) - self.interval = interval - self.cb = self.core.scheduler.addJob(interval, self._periodical, threaded=False) def pluginConfigChanged(self, plugin, name, value): - value *= 60 if name == "interval": - if self.interval != value > self.MIN_INTERVAL: - self.restartPeriodical(value) + interval = value * 60 + if self.MIN_INTERVAL <= interval != self.interval: + self.core.scheduler.removeJob(self.cb) + self.interval = interval + self.initPeriodical() else: - self.logWarning("Cannot change interval: given value is equal to the current or \ - smaller than %s seconds" % self.MIN_INTERVAL) + self.logDebug("Invalid interval value, kept current") + + + def periodical(self): + self.logDebug(_("Restart failed downloads")) + self.core.api.restartFailed() + + + def setup(self): + self.interval = self.MIN_INTERVAL + def coreReady(self): - self.pluginConfigChanged(plugin="RestartFailed", name="interval", value=self.getConfig("interval")) + self.pluginConfigChanged(self.__name__, "interval", self.getConfig("interval")) |