diff options
author | Vuolter <vuolter@gmail.com> | 2013-05-04 09:05:17 +0200 |
---|---|---|
committer | Vuolter <vuolter@gmail.com> | 2013-05-12 14:54:28 +0200 |
commit | 456b8c6f0daf3b2c0d5149c9be50ff213782bdd9 (patch) | |
tree | 3921400b2ed935e8094e13ef2cfbf04add4bd3e3 /module | |
parent | Merge pull request #113 from 4Christopher/stable (diff) | |
download | pyload-456b8c6f0daf3b2c0d5149c9be50ff213782bdd9.tar.xz |
Added fully rewrited RestartFailed plugin, originally by bambie
Diffstat (limited to 'module')
-rw-r--r-- | module/plugins/hooks/RestartFailed.py | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/module/plugins/hooks/RestartFailed.py b/module/plugins/hooks/RestartFailed.py new file mode 100644 index 000000000..5c3a4fbe0 --- /dev/null +++ b/module/plugins/hooks/RestartFailed.py @@ -0,0 +1,69 @@ +# -*- 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: vuolter +""" + +from module.plugins.Hook import Hook +import time + +class RestartFailed(Hook): + __name__ = "RestartFailed" + __version__ = "0.3" + __description__ = "Restart failed packages according to defined rules" + __config__ = [ ("activated", "bool", "Activated" , "True"), + ("on_downloadFailed", "bool", "Restart if downloads fails" , "True"), + ("downloadFailed_number", "int", "Only restart when failed downloads are more than", "5"), + ("downloadFailed_interval", "int", "Only restart when elapsed time since last one is (min)", "10"), + ("on_packageFinished", "bool", "Restart when package finished" , "True") + ("on_reconnect", "bool", "Restart after reconnected" , "True") ] + __author_name__ = ("vuolter") + __author_mail__ = ("vuolter@gmail.com") + + failed = 0 + lastime = 0 + + def checkInterval(self, interval): + interval *= 60 + if now = time() >= lastime + interval : + lastime = now + return True + else + return False + + def downloadFailed(self, pyfile): + if not self.getConfig("on_downloadFailed"): + failed = 0 + return + if failed > number = self.getConfig("downloadFailed_number") + and checkInterval(interval = self.getConfig("downloadFailed_interval")) : + self.core.api.restartFailed() + self.logDebug(self.__name__ + ": executed after " + failed + " downloads failed") + failed = 0 + else + ++failed + + def packageFinished(self, pypack): + if not self.getConfig("on_packageFinished"): + return + self.core.api.restartFailed() + self.logDebug(self.__name__ + ": executed after one package finished") + + def afterReconnecting(self, ip): + if not self.getConfig("on_reconnect"): + return + self.core.api.restartFailed() + self.logDebug(self.__name__ + ": executed after reconnecting") |