Commit c5ab6abe authored by Luc Didry's avatar Luc Didry
Browse files

Start at last checked pad

parent 41c8dd62
......@@ -10,6 +10,8 @@ use Mojo::Util qw(slurp spurt encode);
use Etherpad;
use Data::Dumper;
$SIG{'INT'} = 'INT_handler';
my $c = Config::YAML->new(config => '/etc/delete_after_delay.yml');
my $instance;
......@@ -27,6 +29,14 @@ GetOptions(
print_usage(0) if $help;
print_usage(1) unless ($instance && $c->{$instance});
my ($last, $instance_last);
my $process = 1;
if (-e 'last.'.$instance) {
$last = slurp('last.'.$instance);
$process = 0;
chomp $last;
}
my $ec = Etherpad->new(
url => $c->{$instance}->{url},
apikey => $c->{$instance}->{key},
......@@ -59,6 +69,13 @@ sub delete_after_delay {
$pads->each(
sub {
my ($e, $num) = @_;
if (defined($last) && !$process) {
$process = ($last eq $e);
say sprintf('Skipping %s (waiting to be at %s)', $e, $last);
unlink 'last.'.$instance if $process;
}
return unless $process;
$instance_last = $e;
if (defined($e) && $e ne '') {
say 'Checking pad '.$e if $verbose;
......@@ -87,6 +104,7 @@ sub delete_after_delay {
say 'Deleting '.$e if $verbose;
$ec->delete_pad($e);
$instance_last = undef;
}
} else {
say 'Not deleting '.$e.' since dry-running' if $verbose;
......@@ -146,3 +164,10 @@ EOF
}
exit 1;
}
sub INT_handler {
if (defined($instance_last)) {
spurt $instance_last, 'last.'.$instance;
}
exit(0);
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment