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
@@ -23,14 +23,14 @@ sub new {
23 or return $class->new_failed('no credentials supplied'); 23 or return $class->new_failed('no credentials supplied');
24 } 24 }
25 my $self = $class->SUPER::new($region, $access, $secret); 25 my $self = $class->SUPER::new($region, $access, $secret);
26 if ($token) { 26 if ($token) {
27 # Overwrite the 'sig' attribute. 27 # Overwrite the 'sig' attribute.
28 # FIXME: The attribute itself is not documented, so this 28 # FIXME: The attribute itself is not documented, so this
29 # this method may fail if the internals of the base class 29 # method may fail if the internals of the base class change
30 # change in its future releases. 30 # in its future releases.
31 # This approach works with Net::Amazon::Glacier 0.15 31 # This approach works with Net::Amazon::Glacier 0.15
32 $self->{sig} = new App::Glacier::Signature($self->{sig}, $token); 32 $self->{sig} = new App::Glacier::Signature($self->{sig}, $token);
33 } 33 }
34 return $self; 34 return $self;
35} 35}
36 36
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
@@ -3,12 +3,13 @@ use strict;
3use warnings; 3use warnings;
4use App::Glacier::Core; 4use App::Glacier::Core;
5use parent qw(App::Glacier::Command); 5use parent qw(App::Glacier::Command);
6use Carp; 6use Carp;
7use Data::Dumper; 7use Data::Dumper;
8use App::Glacier::Timestamp; 8use App::Glacier::Timestamp;
9use App::Glacier::Job;
9 10
10=head1 NAME 11=head1 NAME
11 12
12glacier jobs - list Glacier jobs 13glacier jobs - list Glacier jobs
13 14
14=head1 SYNOPSIS 15=head1 SYNOPSIS
@@ -133,13 +134,14 @@ sub list {
133 my $res = $self->glacier->Describe_job($vault, $descr->{JobId}); 134 my $res = $self->glacier->Describe_job($vault, $descr->{JobId});
134 if ($self->glacier->lasterr) { 135 if ($self->glacier->lasterr) {
135 if ($self->glacier->lasterr('code') == 404) { 136 if ($self->glacier->lasterr('code') == 404) {
136 $self->debug(1, "deleting expired $key $vault " . 137 $self->debug(1, "deleting expired $key $vault " .
137 ($descr->{JobDescription} || $descr->{Action}) . 138 ($descr->{JobDescription} || $descr->{Action}) .
138 $descr->{JobId}); 139 $descr->{JobId});
139 $db->delete($key) unless $self->dry_run; 140 App::Glacier::Job->fromdb($self, $vault, $key, $res)->delete()
141 unless $self->dry_run;
140 return; 142 return;
141 } else { 143 } else {
142 $self->error("can't describe job $descr->{JobId}: ", 144 $self->error("can't describe job $descr->{JobId}: ",
143 $self->glacier->last_error_message); 145 $self->glacier->last_error_message);
144 } 146 }
145 } elsif (ref($res) ne 'HASH') { 147 } elsif (ref($res) ne 'HASH') {
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
@@ -39,36 +39,41 @@ sub run {
39 my $db = $self->jobdb(); 39 my $db = $self->jobdb();
40 $db->foreach(sub { 40 $db->foreach(sub {
41 my ($key, $descr) = @_; 41 my ($key, $descr) = @_;
42 my $vault = $descr->{VaultARN}; 42 my $vault = $descr->{VaultARN};
43 $vault =~ s{.*:vaults/}{}; 43 $vault =~ s{.*:vaults/}{};
44 44
45 return if $descr->{Completed}; 45 my $completed = $descr->{Completed};
46 46
47 $self->debug(2, "$descr->{JobId} $descr->{Action} $vault"); 47 $self->debug(2, "$descr->{JobId} $descr->{Action} $vault");
48 if ($descr->{StatusCode} eq 'Failed') { 48 if ($descr->{StatusCode} eq 'Failed') {
49 $self->debug(1, "deleting failed $key $vault " . 49 $self->debug(1,
50 ($descr->{JobDescription} || $descr->{Action}) . 50 "deleting failed $key $vault "
51 $descr->{JobId}); 51 . ($descr->{JobDescription} || $descr->{Action})
52 . ' '
53 . $descr->{JobId});
52 $db->delete($key) unless $self->dry_run; 54 $db->delete($key) unless $self->dry_run;
53 } 55 }
54 56
55 my $res = $self->glacier->Describe_job($vault, $descr->{JobId}); 57 my $res = $self->glacier->Describe_job($vault, $descr->{JobId});
56 if ($self->glacier->lasterr) { 58 if ($self->glacier->lasterr) {
57 if ($self->glacier->lasterr('code') == 404) { 59 if ($self->glacier->lasterr('code') == 404) {
58 $self->debug(1, "deleting expired $key $vault " . 60 $self->debug(1,
59 ($descr->{JobDescription} || $descr->{Action}) . 61 "deleting expired $key $vault "
60 $descr->{JobId}); 62 . ($descr->{JobDescription} || $descr->{Action})
61 $db->delete($key) unless $self->dry_run; 63 . ' '
64 . $descr->{JobId});
65 App::Glacier::Job->fromdb($self, $vault, $key, $res)->delete()
66 unless $self->dry_run;
62 } else { 67 } else {
63 $self->error("can't describe job $descr->{JobId}: ", 68 $self->error("can't describe job $descr->{JobId}: ",
64 $self->glacier->last_error_message); 69 $self->glacier->last_error_message);
65 } 70 }
66 } elsif (ref($res) ne 'HASH') { 71 } elsif (ref($res) ne 'HASH') {
67 croak "describe_job returned wrong datatype (".ref($res).") for \"$descr->{JobId}\""; 72 croak "describe_job returned wrong datatype (".ref($res).") for \"$descr->{JobId}\"";
68 } else { 73 } elsif ($res->{Completed} ne $completed) {
69 $self->debug(2, $res->{StatusCode}); 74 $self->debug(2, $res->{StatusCode});
70 if ($res->{Completed} && $res->{StatusCode} eq 'Succeeded') { 75 if ($res->{Completed} && $res->{StatusCode} eq 'Succeeded') {
71 $self->debug(1, "$descr->{JobId}: processing $descr->{Action} for $vault"); 76 $self->debug(1, "$descr->{JobId}: processing $descr->{Action} for $vault");
72 return if $self->dry_run; 77 return if $self->dry_run;
73 if ($res->{Action} eq 'InventoryRetrieval') { 78 if ($res->{Action} eq 'InventoryRetrieval') {
74 require App::Glacier::Command::Sync; 79 require App::Glacier::Command::Sync;

Return to:

Send suggestions and report system problems to the System administrator.