diff options
Diffstat (limited to 'lib/App/Glacier/Command')
-rw-r--r-- | lib/App/Glacier/Command/Get.pm | 11 | ||||
-rw-r--r-- | lib/App/Glacier/Command/Jobs.pm | 31 | ||||
-rw-r--r-- | lib/App/Glacier/Command/Periodic.pm | 38 |
3 files changed, 14 insertions, 66 deletions
diff --git a/lib/App/Glacier/Command/Get.pm b/lib/App/Glacier/Command/Get.pm index 0d17659..82b32c8 100644 --- a/lib/App/Glacier/Command/Get.pm +++ b/lib/App/Glacier/Command/Get.pm @@ -160,6 +160,8 @@ sub run { if ($job->is_completed) { my $cache_file = $job->cache_file; if (-f $cache_file) { + $self->debug(1, "$job: copying from $cache_file"); + return if $self->dry_run; unless (copy($cache_file, $localname)) { $self->abend(EX_FAILURE, "can't copy $cache_file to $localname: $!"); @@ -193,6 +195,7 @@ use constant TWOMB => 2*MB; sub download { my ($self, $job, $localname) = @_; + my $archive_size = $job->get('ArchiveSizeInBytes'); if ($archive_size < $self->cf_transfer_param(qw(download single-part-size))) { # simple download @@ -214,9 +217,7 @@ sub _open_output { sub _download_simple { my ($self, $job, $localname) = @_; - eval { # FIXME: file_name might be absent - $self->debug(1, "downloading", $job->file_name(1), "in single part"); - }; + $self->debug(1, "$job: downloading in single part"); return if $self->dry_run; my $fd = $self->_open_output($localname); my ($res, $tree_hash) = $self->glacier->Get_job_output($job->vault, @@ -256,8 +257,8 @@ sub _download_multipart { # Compute the number of parts per job my $job_parts = int(($total_parts + $njobs - 1) / $njobs); - $self->debug(1, - "downloading", $job->file_name(1), "to $localname in chunks of $part_size bytes, in $njobs jobs, with $job_parts parts per job"); + $self->debug(1, "$job: downloading in chunks of $part_size bytes, in $njobs jobs, with $job_parts parts per job"); + return if $self->dry_run; use Fcntl qw(SEEK_SET); diff --git a/lib/App/Glacier/Command/Jobs.pm b/lib/App/Glacier/Command/Jobs.pm index 5a5f488..7dc5d06 100644 --- a/lib/App/Glacier/Command/Jobs.pm +++ b/lib/App/Glacier/Command/Jobs.pm @@ -116,43 +116,18 @@ sub list { my $db = $self->jobdb(); $db->foreach(sub { - my ($key, $descr) = @_; - my $vault = $descr->{VaultARN}; - $vault =~ s{.*:vaults/}{}; + my ($key, $descr, $vault) = @_; return if (@vault_names && ! grep { $_ eq $vault } @vault_names); unless ($self->{_options}{cached}) { - if ($descr->{StatusCode} eq 'Failed') { - $self->debug(1, "deleting failed $key $vault " . - ($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}); - 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 { + my $res = $self->check_job($key, $descr, $vault) + or return; $res = timestamp_deserialize($res); $self->debug(2, $res->{StatusCode}); $db->store($key, $res) unless $self->dry_run; $descr = $res; } - } my $started = $self->format_date_time($descr, 'CreationDate'); diff --git a/lib/App/Glacier/Command/Periodic.pm b/lib/App/Glacier/Command/Periodic.pm index 5a4dc2a..39a2d7a 100644 --- a/lib/App/Glacier/Command/Periodic.pm +++ b/lib/App/Glacier/Command/Periodic.pm @@ -7,6 +7,7 @@ use Carp; use Data::Dumper; use File::Basename; use App::Glacier::Job; +use App::Glacier::Command::Get; =head1 NAME @@ -38,39 +39,10 @@ sub run { my $db = $self->jobdb(); $db->foreach(sub { - my ($key, $descr) = @_; - my $vault = $descr->{VaultARN}; - $vault =~ s{.*:vaults/}{}; - - 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}); - $db->delete($key) unless $self->dry_run; - } + my ($key, $descr, $vault) = @_; - 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}); - 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}\""; - } elsif ($res->{Completed} ne $completed) { + my $res = $self->check_job($key, $descr, $vault); + if ($res && $res->{Completed} ne $descr->{Completed}) { $self->debug(2, $res->{StatusCode}); if ($res->{Completed} && $res->{StatusCode} eq 'Succeeded') { $self->debug(1, "$descr->{JobId}: processing $descr->{Action} for $vault"); @@ -86,8 +58,8 @@ sub run { $res->{ArchiveId}); $self->touchdir(dirname($localname)); - require App::Glacier::Command::Get; my $get = clone App::Glacier::Command::Get($self); + $get->option(quiet => 1); $get->download($job, $localname); } } |