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 /module/plugins | |
parent | little fixes (diff) | |
download | pyload-973cfeaf006813c6d9a3cbb163e6b15ec1b46977.tar.xz |
better retry function
Diffstat (limited to 'module/plugins')
-rw-r--r-- | module/plugins/Plugin.py | 21 | ||||
-rw-r--r-- | module/plugins/hoster/RealdebridCom.py | 7 |
2 files changed, 19 insertions, 9 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.")
|