Bio-CIPRES
view release on metacpan or search on metacpan
lib/Bio/CIPRES/Job.pm view on Meta::CPAN
package Bio::CIPRES::Job 0.001;
use 5.012;
use strict;
use warnings;
use overload
'""' => sub {return $_[0]->{handle}};
use Carp;
use Time::Piece;
use XML::LibXML;
use Scalar::Util qw/blessed weaken/;
use List::Util qw/first/;
use Bio::CIPRES::Error;
use Bio::CIPRES::Message;
use Bio::CIPRES::Output;
sub new {
my ($class, %args) = @_;
my $self = bless {}, $class;
croak "Must define user agent" if (! defined $args{agent});
croak "Agent must be an LWP::UserAgent object"
if ( blessed($args{agent}) ne 'LWP::UserAgent' );
$self->{agent} = $args{agent};
weaken( $self->{agent} );
croak "Must define initial status" if (! defined $args{dom});
$self->_parse_status( $args{dom} );
return $self;
}
sub delete {
my ($self) = @_;
my $res = $self->{agent}->delete( $self->{url_status} )
or croak "LWP internal error: $@";
die Bio::CIPRES::Error->new( $res->content )
if (! $res->is_success);
return 1;
}
sub is_finished { return $_[0]->{is_finished} }
sub is_failed { return $_[0]->{is_failed} }
sub poll_interval { return $_[0]->{poll_secs} }
sub submit_time { return $_[0]->{submit_time} }
sub messages { return $_[0]->{messages} }
sub stage {
my ($self) = @_;
# Should be as easy as this:
# return $self->{stage};
# But the docs say:
#
# "Unfortunately, the current version of CIPRES sets
# jobstatus.jobStage in a way that's somewhat inconsistent and difficult
# to explain. You're better off using jobstatus.messages to monitor the
# progress of a job."
#
# so we follow their advice.
#
# Here, we just return the stage text of the last message received
return $self->{messages}->[-1]->stage;
}
sub refresh {
my ($self) = @_;
my $xml = $self->_get( $self->{url_status} );
say "\n", '=' . 80, "\n";
say $xml;
say "\n", '=' . 80, "\n";
my $dom = XML::LibXML->load_xml( string => $xml );
( run in 0.866 second using v1.01-cache-2.11-cpan-39bf76dae61 )