Data-AnyXfer
view release on metacpan or search on metacpan
lib/Data/AnyXfer/Elastic/Import/File/Simple.pm view on Meta::CPAN
my ( $self, $from_item ) = @_;
$from_item ||= $self->item_name;
# deserialise and return the item from storage
my $value = $self->storage->get_item($from_item);
# make sure it deserialises to an array ref
return $value = [@{$self->format->deserialise($value)}]
if $value;
# if we're still alive here
# we don't have a value, so the item must be new or empty
# so just return a ref to an empty array
# (but "touch" the item so it exists if we may need to write)
unless ($self->storage->read_only) {
$self->storage->set_item($from_item, $self->format->serialise([]));
}
return [];
}
lib/Data/AnyXfer/Elastic/Import/SpawnTask/Process.pm view on Meta::CPAN
default => sub {
sub { }
},
);
sub DESTROY { shift->terminate }
=head1 METHODS
=head2 alive
if ( $process->alive ) { }
Check whether the process is still alive.
=cut
sub alive {
my $pid = shift->pid;
kill( 0, $pid ) || $! == POSIX::EPERM;
}
=head2 wait
$process->wait;
Blocks until the process finishes.
=cut
sub wait {
my $self = shift;
sleep 1 while $self->alive;
}
=head2 terminate
$process->terminate;
Attempts to terminate the process. It will try C<SIGHUP>, C<SIGQUIT>,
C<SIGINT>, and C<SIGKILL>, once a second in turn (maximum try count
is 5), before giving up.
=cut
sub terminate {
my $self = shift;
# process is already dead, nothing to do
unless ($self->alive) {
$self->cleanup_sub->();
return 1;
}
# attempt to kill the process, using progressively
# stronger signals
my $pid = $self->pid;
SIGNAL: {
foreach my $signal (qw(HUP QUIT INT KILL)) {
my $count = 5;
while ( $count and $self->alive ) {
--$count;
kill( $signal, $pid );
last SIGNAL unless $self->alive;
sleep 1;
}
}
}
# if it's still alive here, give up and let the current process
# continue
if (!$self->alive) {
$self->cleanup_sub->();
return 1;
} else {
return 0;
}
}
1;
lib/Data/AnyXfer/Elastic/Import/SpawnTask/Remote/Host.pm view on Meta::CPAN
has debug => (
is => 'ro',
isa => Bool,
default => 0,
);
=head1 METHODS
=head2 process_alive
if ( $host->process_is_alive($pid) ) { }
Check whether the process is still alive on the host.
=cut
sub process_is_alive {
my ( $self, $pid ) = @_;
$self->_run_perl(
sprintf 'kill( 0, %s ) || $! == POSIX::EPERM', $pid #
);
}
=head2 wait_for_process
$host->wait_for_process($pid);
Blocks until the process finishes on the host.
=cut
sub wait_for_process {
my ( $self, $pid ) = @_;
sleep 10 while $self->process_is_alive($pid);
}
=head2 terminate_process
$host->terminate_process($pid);
Attempts to terminate the process on the target host.
It will try C<SIGHUP>, C<SIGQUIT>, C<SIGINT>, and C<SIGKILL>,
once a second in turn (maximum try count is 5), before giving up.
=cut
sub terminate_process {
my ( $self, $pid ) = @_;
# process is already dead, nothing to do
return 1 unless $self->process_is_alive($pid);
# attempt to kill the process, using progressively
# stronger signals
SIGNAL: {
foreach my $signal (qw(HUP QUIT INT KILL)) {
my $count = 5;
while ( $count and $self->process_is_alive($pid) ) {
--$count;
$self->_run_perl("kill( \$signal, $pid )");
last SIGNAL unless $self->process_is_alive($pid);
sleep 3;
}
}
}
# if it's still alive here, give up and let the current process
# continue
return !$self->process_is_alive($pid);
}
=head2 run
$host->run(0, qw(bash -c env));
Runs the specified command on the remote host. Command can be supplied
as a list for correct shell quoting (similar to L<system>).
lib/Data/AnyXfer/Elastic/Import/SpawnTask/Remote/Process.pm view on Meta::CPAN
has remote_host => (
is => 'ro',
isa => InstanceOf['Data::AnyXfer::Elastic::Import::SpawnTask::Remote::Host'],
required => 1,
);
=head1 METHODS
=head2 alive
if ( $process->alive ) { }
Check whether the process is still alive.
=cut
sub alive {
my $self = shift;
return $self->remote_host->process_is_alive( $self->pid );
}
=head2 wait
$process->wait;
Blocks until the process finishes.
=cut
lib/Data/AnyXfer/Elastic/Role/Project.pm view on Meta::CPAN
L<Data::AnyXfer::Elastic::ScrollHelper> will be returned instead of
the normal results.
=item C<search_type>
Efficient scrolling can be set by setting the C<search_type> to C<scan>,
saving on the innefficient sorting phase.
=item C<scroll>
Set the duration to keep the results alive, for processing before the next set
of results is fetched. Default is C<5m>.
=back
=head1 ENVIRONMENT
=head2 ES_DEBUG
$ENV{ES_DEBUG} = 1;
( run in 1.075 second using v1.01-cache-2.11-cpan-39bf76dae61 )