summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Vuolter <vuolter@gmail.com> 2013-05-04 13:18:06 +0200
committerGravatar Vuolter <vuolter@gmail.com> 2013-05-12 14:54:30 +0200
commitb99de39af5a5f5201c516d4435414c6d05dd86f3 (patch)
tree64dcb7a69357165eef092c193a4c84fdcb970301
parentAdded fully rewrited RestartFailed plugin, originally by bambie (diff)
downloadpyload-b99de39af5a5f5201c516d4435414c6d05dd86f3.tar.xz
Version 0.4: fixes
-rw-r--r--module/plugins/hooks/RestartFailed.py119
1 files changed, 62 insertions, 57 deletions
diff --git a/module/plugins/hooks/RestartFailed.py b/module/plugins/hooks/RestartFailed.py
index 5c3a4fbe0..24bbe85c4 100644
--- a/module/plugins/hooks/RestartFailed.py
+++ b/module/plugins/hooks/RestartFailed.py
@@ -1,69 +1,74 @@
-# -*- coding: utf-8 -*-
+ # -*- 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 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.
+ 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/>.
+ 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
+ @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")
+ __name__ = "RestartFailed"
+ __version__ = "0.4"
+ __description__ = "Restart failed packages according to defined rules"
+ __config__ = [
+ ("activated", "bool", "Activated", "True"),
+ ("dlFailed", "bool", "Restart if downloads fails", "True"),
+ ("dlFailed_n", "int", "Only when failed downloads are more than", "5"),
+ ("dlFailed_i", "int", "Only when elapsed time since last restart is (min)", "10"),
+ ("packFinished", "bool", "Restart when package finished", "True")
+ ("recnt", "bool", "Restart after reconnected", "True")
+ ]
+ __author_name__ = ("vuolter")
+ __author_mail__ = ("vuolter@gmail.com")
+
+ failed = 0
+ lastime = 0
+
+ def checkInterval(self, interval):
+ now = time()
+ interval *= 60
+ if now >= lastime + interval:
+ lastime = now
+ return True
+ else:
+ return False
+
+ def downloadFailed(self, pyfile):
+ if not self.getConfig("dlFailed"):
+ failed = 0
+ return
+ number = self.getConfig("dlFailed_n")
+ interval = self.getConfig("dlFailed_i")
+ if failed > number and checkInterval(interval):
+ self.core.api.restartFailed()
+ self.logDebug("executed after " + failed + " downloads failed")
+ failed = 0
+ else:
+ failed + 1
+
+ def packageFinished(self, pypack):
+ if not self.getConfig("packFinished"):
+ return
+ self.core.api.restartFailed()
+ self.logDebug("executed after one package finished")
- 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")
+ def afterReconnecting(self, ip):
+ if not self.getConfig("recnt"):
+ return
+ self.core.api.restartFailed()
+ self.logDebug("executed after reconnecting")