diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-06-13 20:15:14 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2011-06-13 20:15:14 +0200 |
commit | 973cfeaf006813c6d9a3cbb163e6b15ec1b46977 (patch) | |
tree | 152a70dce7df0baf488e30c4af2cabb264164298 | |
parent | little fixes (diff) | |
download | pyload-973cfeaf006813c6d9a3cbb163e6b15ec1b46977.tar.xz |
better retry function
-rw-r--r-- | module/plugins/Plugin.py | 21 | ||||
-rw-r--r-- | module/plugins/hoster/RealdebridCom.py | 7 | ||||
-rw-r--r-- | module/remote/thriftbackend/Socket.py | 1 | ||||
-rw-r--r-- | module/web/webinterface.py | 2 |
4 files changed, 21 insertions, 10 deletions
diff --git a/module/plugins/Plugin.py b/module/plugins/Plugin.py index 396069adb..73ce808a6 100644 --- a/module/plugins/Plugin.py +++ b/module/plugins/Plugin.py @@ -118,6 +118,7 @@ class Plugin(object): self.js = self.core.js #: js engine, see `JsEngine` self.cTask = None #captcha task + self.retries = 0 #: amount of retries already made self.html = None #some plugins store html code here self.init() @@ -236,9 +237,23 @@ class Plugin(object): """ fail and indicates file ist temporary offline, the core may take consequences """ raise Fail("temp. offline") - def retry(self): - """ begin again from the beginning """ - raise Retry + def retry(self, max_tries=3, wait_time=1, reason=""): + """Retries and begin again from the beginning + + :param max_tries: number of maximum retries + :param wait_time: time to wait in seconds + :param reason: reason for retrying, will be passed to fail if max_tries reached + """ + if self.retries >= max_tries: + if not reason: reason = "Max retries reached" + raise Fail(reason) + + t = time() + wait_time + while t > time() : + if self.pyfile.abort: raise Abort + + self.retries += 1 + raise Retry(reason) def invalidCaptcha(self): if self.cTask: diff --git a/module/plugins/hoster/RealdebridCom.py b/module/plugins/hoster/RealdebridCom.py index 65a28669a..2d35108bc 100644 --- a/module/plugins/hoster/RealdebridCom.py +++ b/module/plugins/hoster/RealdebridCom.py @@ -80,10 +80,5 @@ class RealdebridCom(Hoster): if check == "error":
#usual this download can safely be retried
- if self.tries < 3:
- self.tries += 1
- sleep(1)
- self.retry()
- else:
- self.fail("An error occured while generating link.")
+ self.retry(reason="An error occured while generating link.")
diff --git a/module/remote/thriftbackend/Socket.py b/module/remote/thriftbackend/Socket.py index dc201c431..3f837bdae 100644 --- a/module/remote/thriftbackend/Socket.py +++ b/module/remote/thriftbackend/Socket.py @@ -45,6 +45,7 @@ class Socket(TSocket): def open(self): if self.ssl: + #TODO check SSL = __import__("OpenSSL", globals(), locals(), "SSL", -1).SSL WantReadError = SSL.WantReadError ctx = SSL.Context(SSL.SSLv23_METHOD) diff --git a/module/web/webinterface.py b/module/web/webinterface.py index 17be5c3b3..69e67f9e4 100644 --- a/module/web/webinterface.py +++ b/module/web/webinterface.py @@ -98,7 +98,7 @@ session_opts = { web = StripPathMiddleware(SessionMiddleware(app(), session_opts)) web = GZipMiddleWare(web) -#install(otfcompress) +#TODO: compress plugin, install(otfcompress) import pyload_app import json_app |