Skip to content

Commit

Permalink
Fix retry to behave like a retry.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Thomson authored and Andrew Thomson committed Jul 26, 2012
1 parent 2d3c022 commit 6016f10
Showing 1 changed file with 10 additions and 23 deletions.
33 changes: 10 additions & 23 deletions retry
@@ -1,44 +1,32 @@
#!/usr/bin/perl

#
# Repeats some script untill success.
# Repeats some action until there are n failed attemps, or a success.
#

use strict;
use warnings;
use Getopt::Long;

my $sleep = 0;
my $repeat = 1;
my $retry = 1;
my @arguments = ();

my $result = GetOptions(
"sleep=i" => \$sleep,
"repeat=i" => \$repeat) or die usage("Invalid input $!");
"retry=i" => \$retry) or die usage("Invalid input $!");

my $successes = 0;
my $failures = 0;

do
do
{
my $result_str;
$result = fire(@ARGV);
if ($result) {
$result_str = "Failure";
$failures ++;
} else {
$result_str = "Success";
$successes ++;
if ($result == 0) {
exit(0);
}

my $attempts = $successes + $failures;
my $rate = $successes / $attempts;

print "$result_str $successes/$attempts $rate\n";

$repeat --;
$retry --;
sleep $sleep;
} while($repeat);
} while($retry);
exit(1);

sub fire {
my $pid = fork();
Expand All @@ -59,7 +47,6 @@ sub usage {
print STDERR "$msg\n";
print STDERR "retry [--sleep time] [--retry count] -- program args...\n";
print STDERR "Runs program with arguments args count times\n";
print STDERR "sleeping time between attempts.\n";
print STDERR "Prints success statistics between runs\n";
print STDERR "seconds to sleep between attempts.\n";
}

0 comments on commit 6016f10

Please sign in to comment.