diff options
author | Walter Purcaro <vuolter@gmail.com> | 2014-07-05 22:35:14 +0200 |
---|---|---|
committer | Walter Purcaro <vuolter@gmail.com> | 2014-07-05 22:35:14 +0200 |
commit | c9c16f69e39580ae7744b05f60268578e6032563 (patch) | |
tree | af0957e7790a6cc4f50ef4381c6cb8f0a0ee6be0 /module | |
parent | [BayfilesCom] Fix https://github.com/pyload/pyload/issues/575 (diff) | |
download | pyload-c9c16f69e39580ae7744b05f60268578e6032563.tar.xz |
[RestartFailed] Code cleanup
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/hooks/RestartFailed.py | 65 |
1 files changed, 30 insertions, 35 deletions
diff --git a/module/plugins/hooks/RestartFailed.py b/module/plugins/hooks/RestartFailed.py index 85553d738..89bbcb19e 100644 --- a/module/plugins/hooks/RestartFailed.py +++ b/module/plugins/hooks/RestartFailed.py @@ -1,57 +1,52 @@ # -*- 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 -""" +############################################################################ +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero 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 Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +############################################################################ from module.plugins.Hook import Hook class RestartFailed(Hook): __name__ = "RestartFailed" - __version__ = "1.53" + __version__ = "1.54" __description__ = """Periodically restart all failed downloads in queue""" __config__ = [("activated", "bool", "Activated", False), - ("interval", "int", "Interval in minutes", 90)] + ("interval", "int", "Check interval in minutes", 90)] __author_name__ = "Walter Purcaro" __author_mail__ = "vuolter@gmail.com" + MIN_INTERVAL = 15 * 60 #: 15m minimum check interval (value is in seconds) + event_list = ["pluginConfigChanged"] - MIN_INTERVAL = 15 * 60 # seconds def periodical(self): - self.logDebug("Restart all failed downloads now") + self.logInfo("Restart failed downloads") self.core.api.restartFailed() - 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) + if name != "interval": + 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.logWarning("Invalid interval value, kept current") + + 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")) |