AnyEvent-Consul-Exec
view release on metacpan or search on metacpan
lib/AnyEvent/Consul/Exec.pm view on Meta::CPAN
use strict;
use experimental qw(postderef);
use Consul 0.022;
use AnyEvent;
use AnyEvent::Consul;
use JSON::MaybeXS;
use Type::Params qw(compile);
use Types::Standard qw(ClassName Dict Str Optional CodeRef ArrayRef Int slurpy);
my @callbacks = map { "on_$_" } qw(submit ack output exit done error);
sub new {
state $check = compile(
ClassName,
slurpy Dict[
command => Str,
wait => Optional[Int],
dc => Optional[Str],
node => Optional[Str],
min_node_count => Optional[Int],
service => Optional[Str],
tag => Optional[Str],
consul_args => Optional[ArrayRef],
map { $_ => Optional[CodeRef] } @callbacks,
],
);
my ($class, $self) = $check->(@_);
map { $self->{$_} //= sub {} } @callbacks;
$self->{wait} //= 2;
$self->{consul_args} //= [];
$self->{dc_args} = $self->{dc} ? [dc => $self->{dc}] : [];
$self->{min_node_count} //= 0;
return bless $self, $class;
}
sub _wait_responses {
my ($self, $index) = @_;
lib/AnyEvent/Consul/Exec.pm view on Meta::CPAN
my $e = AnyEvent::Consul::Exec->new(
command => 'uptime',
);
Then call C<start> to kick it off:
$e->start;
As the C<AnyEvent> event loop progresses, the command will be executed on
remote nodes. Output and results of that command on each node will be posted to
callbacks you can optionally provide to the constructor.
When calling the constructor, you can include the C<consul_args> option with an
arrayref as a value. Anything in that arrayref will be passed as-is to the
C<AnyEvent::Consul> constructor. Use this to set the various client options
documented in L<AnyEvent::Consul> and L<Consul>.
The C<wait> option will tell the target agent how long to wait, without
receiving output, before killing the command. This does the same thing as the
C<-wait> option to C<consul exec>.
lib/AnyEvent/Consul/Exec.pm view on Meta::CPAN
node => /^(host1|host2|host3)$/,
min_node_count => 3,
The C<dc> option can take the name of the datacenter to run the command in. The
exec mechanism is limited to a single datacentre. This option will cause
L<AnyEvent::Consul::Exec> to find a Consul agent in the named datacenter and
execute the command there (without it, the local node is used).
=head1 CALLBACKS
C<AnyEvent::Consul::Exec> will arrange for various callbacks to be called as
the command is run on each node and its output and exit code returned. Set this
up by passing code refs to the constructor:
=over 4
=item * C<on_submit>
Called when the command is fully accepted by Consul (ie in the KV store, ready
for nodes to find).
( run in 0.737 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )