The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

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

VERSION

version 1.000001

SYNOPSIS

    use Email::Sender::Server::Manager;

    my $manager = Email::Sender::Server::Manager->new;

    # set some email message attributes
    my @message = (to => '...', subject => '...', body => '...');

    # record an email message
    $manager->create_work(@message);

    # delegate and process all recorded 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 email processing.

ATTRIBUTES

spawn

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

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.

workspace

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

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.

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 any existing email message attributes, see Email::Sender::Server::Message for more details, when the messages are created.

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

    $mgr->create_config;

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

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

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.

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

    my @message  = (to => '...', subject => '...', body => '...');

    my $filepath = $mgr->create_work(@message);

    print "file has been queued" if -f $filepath;
    print "file has been processed" if -f $filepath;

delegate_workload

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

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

    $mgr->delegate_workload; # blocking

AUTHOR

Al Newkirk <anewkirk@ana.io>

COPYRIGHT AND LICENSE

This software is copyright (c) 2010 by Al Newkirk.

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