NAME
Data::AnyXfer::Elastic::Import::SpawnTask - Play an import in a separate background process
SYNOPSIS
use Path::Class ();
use Data::AnyXfer::Elastic ();
use Data::AnyXfer::Elastic::Import::DataFile ();
use Data::AnyXfer::Elastic::Import::SpawnTask ();
my $datafile = Data::AnyXfer::Elastic::Import::DataFile->new(
file => Path::Class::file( 'my_data.datafile' )
);
# generate a task per client
my @process_list;
my $elastic = Data::AnyXfer::Elastic->new;
foreach ($elastic->all_clients_for('public_data')) {
my @args = (
datafile => $datafile,
client => $_,
verbose => 1,
delete_before_create => 1,
);
push @process_list,
Data::AnyXfer::Elastic::Import::SpawnTask->run(@args);
}
# wait for the tasks to complete
foreach (@process_list) { $_->wait() }
DESCRIPTION
This module allows us to play a datafile using Data::AnyXfer::Elastic::Importer, asynchronously, using a background process.
The background process will be spun up as a new process. You will be returned a process object which you can inspect to track progress.
ATTRIBUTES
For internal use only.
METHODS
run
my $process = Data::AnyXfer::Elastic::Import::SpawnTask->run(
datafile => $datafile,
client => $_,
verbose => 1,
delete_before_create => 1,
debug => 1,
);
do_something(); # do something in the meantime
$process->wait(); # wait for the import to complete
This is the primary method in this module (It should be called as a class method).
It takes a named argument list, and returns a Proc::Background instance representing the import process. The process will die once the import is complete, so if you need to you can call wait
to synchronise.
COPYRIGHT
This software is copyright (c) 2019, Anthony Lucas.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.