API-Eulerian
view release on metacpan or search on metacpan
lib/API/Eulerian/EDW/Peer/Thin.pm view on Meta::CPAN
$hook->on_replace( $json->{ uuid }, $json->{ rows } );
}
case 'headers' {
#print Dumper( $json ) . "\n";
$self->{ uuid } = $uuid;
$hook->on_headers(
$json->{ uuid }, $json->{ timerange }->[ 0 ],
$json->{ timerange }->[ 1 ], $json->{ columns }
);
}
case 'progress' {
$hook->on_progress(
$json->{ uuid }, $json->{ progress }
);
}
case 'status' {
$hook->on_status(
$json->{ uuid }, $json->{ aes }, $json->{ status }->[ 1 ],
$json->{ status }->[ 0 ], $json->{ status }->[ 2 ]
);
}
else {}
}
}
#
# @brief Join Websocket stream, raise callback hook accordingly to received
# messages types.
#
# @param $self - API::Eulerian::EDW::Peer:Thin instance.
# @param $rc - Reply context of JOB creation.
#
# @return Reply context.
#
sub join
{
my ( $self, $status ) = @_;
my $json = API::Eulerian::EDW::Request->json( $status->{ response } );
my $ws = API::Eulerian::EDW::WebSocket->new(
$self->host(), $self->ports()->[ $self->secure() ]
);
my $url = $self->url( $json->{ aes } );
$ws->{ _THIN } = $self;
return $ws->join( $url, \&dispatcher );
}
#
# @brief Do Request on Eulerian Data Warehouse Platform.
#
# @param $self - Eulerian Data Warehouse Peer.
# @param $command - Eulerian Data Warehouse Command.
#
sub request
{
my ( $self, $command ) = @_;
my $bench = new API::Eulerian::EDW::Bench();
my $response;
my $status;
my $json;
# Create Job on Eulerian Data Warehouse Platform
$bench->start();
$status = $self->create( $command );
$bench->stage( 'create' );
if( ! $status->error() ) {
# Join Websocket call user specific callback hook
$bench->start();
$status = $self->join( $status );
$bench->stage( 'join' );
$status->{ bench } = $bench;
}
return $status;
}
#
# @brief Cancel Job on Eulerian Data Warehouse Platform.
#
# @param $self - API::Eulerian::EDW::Peer::Rest instance.
# @param $rc - Reply context.
#
sub cancel
{
my ( $self ) = @_;
my $status;
# Get Valid Headers
$status = $self->headers();
if( ! $status->error() && exists( $self->{ uuid } ) ) {
my $uuid = $self->{ uuid };
my $command = "KILL $uuid;";
# Post new JOB to Eulerian Data Warehouse Platform
$status = API::Eulerian::EDW::Request->post(
$self->url(), $status->{ headers }, $command, 'text/plain'
);
}
return $status;
}
#
# End Up module properly
#
1;
( run in 0.321 second using v1.01-cache-2.11-cpan-5735350b133 )