Skip to content

Instantly share code, notes, and snippets.

@semifor
Created March 7, 2012 16:55
Show Gist options
  • Select an option

  • Save semifor/1994362 to your computer and use it in GitHub Desktop.

Select an option

Save semifor/1994362 to your computer and use it in GitHub Desktop.
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