helm
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Helm/Log/Channel/email.pm view on Meta::CPAN
package Helm::Log::Channel::email;
use strict;
use warnings;
use Moose;
use namespace::autoclean;
use DateTime;
BEGIN {
eval { require Email::Simple };
die "Could not load Email::Simple. It must be installed to use Helm's email logging" if $@;
eval { require Email::Simple::Creator };
die "Could not load Email::Simple::Creator. It must be installed to use Helm's email logging" if $@;
eval { require Email::Sender::Simple };
die "Could not load Email::Sender::Simple. It must be installed to use Helm's email logging" if $@;
eval { require Email::Valid };
die "Could not load Email::Valid::Simple. It must be installed to use Helm's email logging" if $@;
}
extends 'Helm::Log::Channel';
has email_address => (is => 'ro', writer => '_email_address', isa => 'Str');
has email_body => (is => 'ro', writer => '_email_body', isa => 'Str', default => '');
has from => (is => 'ro', writer => '_from', isa => 'Str', default => '');
has is_parallel => (is => 'ro', writer => '_is_parallel', isa => 'Bool', default => 0);
has is_parent => (is => 'ro', writer => '_is_parent', isa => 'Bool', default => 0);
has pipes => (is => 'ro', writer => '_pipes', isa => 'HashRef', default => sub { {} });
# fork off an IO worker which has a pipe for each server we're going to do work
# on. Use that pipe to communicate with the process doing the parallel work
# on that server. So when another child process does $helm->log->info... that
# output will end up going from that child process over a pipe reserved for that
# process's server, to this IO worker process which will then append it to the email body.
sub parallelize {
my ($self, $helm) = @_;
$self->_is_parallel(1);
# if we're going to do parallel stuff, then create a pipe for each server now
# that we can use to communicate with the child processes later
Helm->debug("Creating a pipe for each server target for multiplexing output");
my %pipes = map { $_->name => IO::Pipe->new } (@{$helm->servers});
# and one for the parent so it's handled like everything else
Helm->debug("Parent process should also communicate over multiplexing pipes");
my $parent_pipe = IO::Pipe->new();
$pipes{parent} = $parent_pipe;
$self->_pipes(\%pipes);
# fork off an IO worker process
my $pid = fork();
$helm->die("Couldn't fork email IO worker process") if !defined $pid;
if ($pid) {
# parent here
$self->_is_parent(1);
Helm->debug("Parent process pipe is a writer");
$parent_pipe->writer;
$parent_pipe->autoflush(1);
} else {
# child here
my %pipe_cleaners;
my $all_clean = AnyEvent->condvar;
Helm->debug("Child process pipes are readers");
foreach my $server (keys %pipes) {
my $pipe = $pipes{$server};
$pipe->reader;
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.473 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )