Added option --age to expire all instances beyond a certain age.
This commit is contained in:
parent
810552e10f
commit
cd48a38516
|
@ -9,6 +9,7 @@ use strict;
|
|||
|
||||
use Simba::CA;
|
||||
use Bit::Vector::Judy;
|
||||
use Getopt::Long;
|
||||
|
||||
$| = 1;
|
||||
|
||||
|
@ -18,6 +19,24 @@ my $ca = Simba::CA->new({
|
|||
|
||||
my $dbh = $ca->{dbh};
|
||||
|
||||
my %opt;
|
||||
GetOptions(
|
||||
\%opt,
|
||||
"age=s");
|
||||
|
||||
if ($opt{age}) {
|
||||
my ($num, $unit) = $opt{age} =~ /(\d(?:.\d+)?)(y|m|w|d)/;
|
||||
my $scale = { y => 365 * 86400,
|
||||
m => 30 * 86400,
|
||||
w => 7 * 86400,
|
||||
d => 1 * 86400 }->{$unit};
|
||||
die "unknown time unit $unit" unless $scale;
|
||||
my $expired_sessions
|
||||
= $dbh->selectcol_arrayref("select id from sessions where start_date < ? order by id",
|
||||
{},
|
||||
time() - $num * $scale);
|
||||
push @ARGV, @$expired_sessions;
|
||||
}
|
||||
for my $session (@ARGV) {
|
||||
print "deleting instances of session $session\n";
|
||||
my $n_instances = $dbh->do("delete from instances where session=?", {}, $session);
|
||||
|
|
Loading…
Reference in New Issue