Skip Menu |

This queue is for tickets about the Net-Amazon-Glacier CPAN distribution.

Report information
The Basics
Id: 79657
Status: resolved
Priority: 0/
Queue: Net-Amazon-Glacier

People
Owner: TIM [...] cpan.org
Requestors: treed [...] imvu.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [patch] Job Operations
Date: Fri, 14 Sep 2012 16:38:10 -0700
To: bug-Net-Amazon-Glacier [...] rt.cpan.org, Operations <operations [...] imvu.com>
From: Ted Reed <treed [...] imvu.com>
Hi! We're using Net::Amazon::Glacier for a project and wrote support for job operations. We (IMVU) contribute this code specifically under the GPL Version 1 and Artistic License (Perl) Version 1. I attempted to follow the coding conventions I could discern, but it's possible I forgot something or didn't notice something. --- Net-Amazon-Glacier-0.09/lib/Net/Amazon/Glacier.pm 2012-09-04 10:17:12.000000000 -0700 +++ Net-Amazon-Glacier-0.10/lib/Net/Amazon/Glacier.pm 2012-09-11 18:06:46.000000000 -0700 @@ -161,6 +161,107 @@ } } +=head1 JOB OPERATIONS + +=head2 initiate_archive_retrieval( $vault_name, $archive_id, [ $description, $sns_topic ] ) + +Initiates an archive retrieval job. $archive_id is an ID previously retrieved from Amazon Glacier. A job description of up to 1,024 printable ASCII characters may be supplied. An SNS Topic to send notifications to upon job completion may also be supplied. + +=cut + +sub initiate_archive_retrieval { + my ( $self, $vault_name, $archive_id, $description, $sns_topic ) = @_; + croak "no vault name given" unless $vault_name; + croak "no archive id given" unless $archive_id; + + my $content_raw = { + Type => 'archive-retrieval', + ArchiveId => $archive_id, + }; + + $content_raw->{Description} = $description + if defined($description); + + $content_raw->{SNSTopic} = $sns_topic + if defined($sns_topic); + + my $res = $self->_send_receive( + POST => "/-/vaults/$vault_name/jobs", + [ ], + encode_json($content_raw), + ); + + return 0 unless $res->is_success; + return $res->header('x-amz-job-id'); +} + +=head2 initiate_inventory_retrieval( $vault_name, [ $format, $description, $sns_topic ] ) + +Initiates an archive retrieval job. $archive_id is an ID previously retrieved from Amazon Glacier. A job description of up to 1,024 printable ASCII characters may be supplied. An SNS Topic to send notifications to upon job completion may also be supplied. + +=cut + +sub initiate_inventory_retrieval { + my ( $self, $vault_name, $format, $description, $sns_topic ) = @_; + croak "no vault name given" unless $vault_name; + + my $content_raw = { + Type => 'inventory-retrieval', + }; + + $content_raw->{Format} = $format + if defined($format); + + $content_raw->{Description} = $description + if defined($description); + + $content_raw->{SNSTopic} = $sns_topic + if defined($sns_topic); + + my $res = $self->_send_receive( + POST => "/-/vaults/$vault_name/jobs", + [ ], + encode_json($content_raw), + ); + + return 0 unless $res->is_success; + return $res->header('x-amz-job-id'); +} + +=head2 get_job_output( $vault_name, $job_id, [ $range ] ) + +Retrieves the output of a job, returns a binary blob. Optional range parameter is passed as an HTTP header. + +=cut + +sub get_job_output { + my ( $self, $vault_name, $job_id, $range ) = @_; + + my $headers = []; + + push @$headers, (Range => $range) + if defined($range); + + my $res = $self->_send_receive( GET => "/-/vaults/$vault_name/jobs/$job_id/output", $headers ); + if ( $res->is_success ) { + return $res->decoded_content; + } else { + return undef; + } +} + +=head2 describe_job( $vault_name, $job_id ) + +Retrieves a hashref with information about the requested JobID + +=cut + +sub describe_job { + my ( $self, $vault_name, $job_id ) = @_; + my $res = $self->_send_receive( GET => "/-/vaults/$vault_name/jobs/$job_id" ); + return $self->_decode_and_handle_response( $res ); +} +

Message body is not shown because it is too large.

Thank you for your contribution! I've applied the patch in version 0.10.