NAME

Parallel::Boss - manage worker processes

VERSION

This document describes Parallel::Boss version 0.01

SYNOPSIS

use Parallel::Boss;

my $worker = sub {
    my ( $boss, @args ) = @_;
    while ( $boss->is_watching ) {

        # pretend to be working
        ...;
    }
};

Parallel::Boss->run(
    num_workers => 4,
    args        => \@args,
    worker      => $worker,
);

DESCRIPTION

Module running specified number of worker processes.

METHODS

run

$class->run(%params)

start specified number of workers and supervise them. If any of the workers exits, a new one will be started as a replacement. If parent process receives HUP signal, then it sends HUP signal to every worker process and restarts workers if they exit. If parent process receives INT, QUIT, or TERM, it sends TERM to all workers, waits for up to 15 seconds till they all exit, and sends KILL to those workers that are still running, after all workers exited the run method returns.

The following parameters are accepted:

num_workers

number of workers to start

args

reference to array of arguments that should be passed to worker subroutine

worker

subroutine that will be executed by every worker. If it returns, the worker process exits. The subroutine passed the Parallel::Boss object as the first argument, and array specified by args as the following arguments.

is_watching

$boss->is_watching

this method should be periodically invoked by the worker process. It checks if the parent process is still running, if not the worker should exit.

AUTHOR

Pavel Shaydo <zwon at cpan.org>

LICENSE AND COPYRIGHT

Copyright (C) 2016 Pavel Shaydo

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.