mirror of
https://github.com/mitb-archive/filebot
synced 2024-11-02 08:25:02 -04:00
* added retry { ... } construct
This commit is contained in:
parent
a7822901f8
commit
99a2013153
@ -359,3 +359,20 @@ def tryQuietly(c) {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry given closure until it returns successfully (indefinitely by default)
|
||||
*/
|
||||
def retry(n = -1, quiet = false, c) {
|
||||
for(int i = 1; i <= n; i++) {
|
||||
try {
|
||||
return c.call()
|
||||
} catch(Throwable e) {
|
||||
if (i >= 0 && i >= n) {
|
||||
throw e
|
||||
} else if (!quiet) {
|
||||
_log.warning("retry $i: ${e.class.simpleName}: ${e.message}")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user