aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2018-12-18 20:33:46 +0200
committerSergey Poznyakoff <gray@gnu.org>2018-12-18 20:33:46 +0200
commit249512af92d3f592ae683279c2cd1f54a7c1a726 (patch)
treee71528045c19978bac042c7d6f52cc3485d4feea
parent728992688946fe88173e7cd561456a10c9d23fd8 (diff)
downloadglacier-249512af92d3f592ae683279c2cd1f54a7c1a726.tar.gz
glacier-249512af92d3f592ae683279c2cd1f54a7c1a726.tar.bz2
Fix periodic subcommand
-rw-r--r--lib/App/Glacier/Bre.pm4
-rw-r--r--lib/App/Glacier/Command/Jobs.pm4
-rw-r--r--lib/App/Glacier/Command/Periodic.pm23
3 files changed, 19 insertions, 12 deletions
diff --git a/lib/App/Glacier/Bre.pm b/lib/App/Glacier/Bre.pm
index 3b1d190..cd9fb84 100644
--- a/lib/App/Glacier/Bre.pm
+++ b/lib/App/Glacier/Bre.pm
@@ -17,26 +17,26 @@ sub new {
my ($secret,$token);
if (defined($access)) {
$secret = delete $opts{secret}
or $class->new_failed('secret not supplied');
} else {
($access, $secret, $token) = _get_instore_creds()
or return $class->new_failed('no credentials supplied');
}
my $self = $class->SUPER::new($region, $access, $secret);
if ($token) {
# Overwrite the 'sig' attribute.
# FIXME: The attribute itself is not documented, so this
- # this method may fail if the internals of the base class
- # change in its future releases.
+ # method may fail if the internals of the base class change
+ # in its future releases.
# This approach works with Net::Amazon::Glacier 0.15
$self->{sig} = new App::Glacier::Signature($self->{sig}, $token);
}
return $self;
}
sub new_failed {
my ($class, $message) = @_;
bless { _error => $message }, $class;
}
my $istore_base_url = "http://169.254.169.254/latest/";
diff --git a/lib/App/Glacier/Command/Jobs.pm b/lib/App/Glacier/Command/Jobs.pm
index 736d713..5a5f488 100644
--- a/lib/App/Glacier/Command/Jobs.pm
+++ b/lib/App/Glacier/Command/Jobs.pm
@@ -1,20 +1,21 @@
package App::Glacier::Command::Jobs;
use strict;
use warnings;
use App::Glacier::Core;
use parent qw(App::Glacier::Command);
use Carp;
use Data::Dumper;
use App::Glacier::Timestamp;
+use App::Glacier::Job;
=head1 NAME
glacier jobs - list Glacier jobs
=head1 SYNOPSIS
B<glacier jobs>
[B<-cl>]
[B<--cached>]
[B<--long>]
[B<--time-style=>B<default>|B<full-iso>|B<long-iso>|B<iso>|B<locale>|B<+I<FORMAT>>]
@@ -127,25 +128,26 @@ sub list {
($descr->{JobDescription} || $descr->{Action}) .
$descr->{JobId});
$db->delete($key) unless $self->dry_run;
return;
}
my $res = $self->glacier->Describe_job($vault, $descr->{JobId});
if ($self->glacier->lasterr) {
if ($self->glacier->lasterr('code') == 404) {
$self->debug(1, "deleting expired $key $vault " .
($descr->{JobDescription} || $descr->{Action}) .
$descr->{JobId});
- $db->delete($key) unless $self->dry_run;
+ App::Glacier::Job->fromdb($self, $vault, $key, $res)->delete()
+ unless $self->dry_run;
return;
} else {
$self->error("can't describe job $descr->{JobId}: ",
$self->glacier->last_error_message);
}
} elsif (ref($res) ne 'HASH') {
croak "describe_job returned wrong datatype (".ref($res).") for \"$descr->{JobId}\"";
} else {
$res = timestamp_deserialize($res);
$self->debug(2, $res->{StatusCode});
$db->store($key, $res) unless $self->dry_run;
$descr = $res;
diff --git a/lib/App/Glacier/Command/Periodic.pm b/lib/App/Glacier/Command/Periodic.pm
index 51c9718..5a4dc2a 100644
--- a/lib/App/Glacier/Command/Periodic.pm
+++ b/lib/App/Glacier/Command/Periodic.pm
@@ -33,48 +33,53 @@ your crontab, e.g.:
=cut
sub run {
my $self = shift;
my $db = $self->jobdb();
$db->foreach(sub {
my ($key, $descr) = @_;
my $vault = $descr->{VaultARN};
$vault =~ s{.*:vaults/}{};
- return if $descr->{Completed};
+ my $completed = $descr->{Completed};
$self->debug(2, "$descr->{JobId} $descr->{Action} $vault");
if ($descr->{StatusCode} eq 'Failed') {
- $self->debug(1, "deleting failed $key $vault " .
- ($descr->{JobDescription} || $descr->{Action}) .
- $descr->{JobId});
+ $self->debug(1,
+ "deleting failed $key $vault "
+ . ($descr->{JobDescription} || $descr->{Action})
+ . ' '
+ . $descr->{JobId});
$db->delete($key) unless $self->dry_run;
}
my $res = $self->glacier->Describe_job($vault, $descr->{JobId});
if ($self->glacier->lasterr) {
if ($self->glacier->lasterr('code') == 404) {
- $self->debug(1, "deleting expired $key $vault " .
- ($descr->{JobDescription} || $descr->{Action}) .
- $descr->{JobId});
- $db->delete($key) unless $self->dry_run;
+ $self->debug(1,
+ "deleting expired $key $vault "
+ . ($descr->{JobDescription} || $descr->{Action})
+ . ' '
+ . $descr->{JobId});
+ App::Glacier::Job->fromdb($self, $vault, $key, $res)->delete()
+ unless $self->dry_run;
} else {
$self->error("can't describe job $descr->{JobId}: ",
$self->glacier->last_error_message);
}
} elsif (ref($res) ne 'HASH') {
croak "describe_job returned wrong datatype (".ref($res).") for \"$descr->{JobId}\"";
- } else {
+ } elsif ($res->{Completed} ne $completed) {
$self->debug(2, $res->{StatusCode});
if ($res->{Completed} && $res->{StatusCode} eq 'Succeeded') {
$self->debug(1, "$descr->{JobId}: processing $descr->{Action} for $vault");
return if $self->dry_run;
if ($res->{Action} eq 'InventoryRetrieval') {
require App::Glacier::Command::Sync;
my $sync = clone App::Glacier::Command::Sync($self);
$sync->sync($vault);
} elsif ($res->{Action} eq 'ArchiveRetrieval') {
my $job = App::Glacier::Job->fromdb($self, $vault,
$key, $res);
my $localname = $self->archive_cache_filename($vault,

Return to:

Send suggestions and report system problems to the System administrator.