Created
March 7, 2012 16:55
-
-
Save semifor/1994362 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sub nt_with_retry { | |
| my ( $nt, $method, @args ) = @_; | |
| my $result; | |
| my $redo = 0; | |
| my $delay = 0.25; | |
| do { | |
| try { | |
| $result = $nt->$method(@args); | |
| } | |
| catch { | |
| die $_ if $_->code < 500; | |
| local $\ = undef; | |
| print "Trying again."; | |
| print STDERR $_; | |
| $redo++; | |
| sleep $delay; | |
| $delay *= 2; | |
| } | |
| } while ($redo > 0 && $redo < 11); | |
| return $result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment