The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Email::Sender::Server::Manager - Email Server Manager

VERSION

version 0.50

SYNOPSIS

    use Email::Sender::Server::Manager;
    
    my $manager = Email::Sender::Server::Manager->new;
    
    # create a list of Email::Sender::Server::Message attribute values
    
    my @message = (
        to      => '...',
        subject => '...',
        body    => '...',
    );
    
    # validate and record an email message
    
    $manager->create_work(@message);
    
    # delegate and process email messages
    
    $manager->process_workload; # blocking

DESCRIPTION

Email::Sender::Server::Manager is responsible for communicating messages between the client, server and workers. Specifically, this class is responsible for queuing and assigning email requests to worker processes for eventual delivery.

See Email::Sender::Server::Worker for more information about that process.

ATTRIBUTES

spawn

The spawn attribute represents the number of workers to create when processing the email queue. This attribute defaults to 3 (worker processes).

    use Email::Sender::Server::Manager;
    
    my $mgr = Email::Sender::Server::Manager->new(
        spawn => 10
    );

workers

The workers attribute contains an arrayref of worker process IDs. This value is empty by default and is set internally by the process_workload() method.

    use Email::Sender::Server::Manager;
    
    my $mgr = Email::Sender::Server::Manager->new;
    
    $mgr->workers;

workspace

The workspace attribute contains the directory path to the queued ess_data directory.

    use Email::Sender::Server::Manager;
    
    my $mgr = Email::Sender::Server::Manager->new;
    
    $mgr->workspace;

METHODS

cleanup

The cleanup method restores the data directory to its initial state, re-queuing any emails assigned to workers which haven't been processed yet.

    use Email::Sender::Server::Manager;
    
    my $mgr = Email::Sender::Server::Manager->new;
    
    $mgr->cleanup;

create_config

The create_config method writes a config file to the data directory unless one exists. The config, if present, will be merge with Email::Sender::Server::Message attributes when messages are created (e.g. the create_work method).

    use Email::Sender::Server::Manager;
    
    my $mgr = Email::Sender::Server::Manager->new;
    
    $mgr->create_config;

... which creates a config file (e.g. in ./ess_data/config) containing:

    $VAR1 = {
        
        message {
            
            to   => '...',
            from => '...',
            
        },
        
        transport => {
            
            SMTP => {
                
                host => '...',
                port => '...'
                
            }
            
        }
        
    };

... elsewhere in your codebase

    use Email::Sender::Server::Manager;
    
    my $mgr = Email::Sender::Server::Manager->new;
    
    # to, from, and transport taken from the config if not set
    
    $mgr->create_work(subject => '...', text => '...');

create_work

The create_work method writes a message file to the data directory queuing it to be process by the next selected worker process. It returns the absolute path to the queued email message unless message validation failed.

    use Email::Sender::Server::Manager;
    
    my $mgr = Email::Sender::Server::Manager->new;
    
    my @message = (
        to      => '...',
        subject => '...',
        body    => '...',
    );
    
    my $filepath = $mgr->create_work(@message);
    
    unless ($filepath) {
        
        print $mgr->errors_to_string;
        
    }

delegate_workload

The delegate_workload method creates a number of worker processes based on the spawn attribute, forks itself and blocks until shutdown.

    use Email::Sender::Server::Manager;
    
    my $mgr = Email::Sender::Server::Manager->new;
    
    $mgr->delegate_workload; # blocking

AUTHOR

Al Newkirk <awncorp@cpan.org>

COPYRIGHT AND LICENSE

This software is copyright (c) 2012 by awncorp.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.