DESCRIPTION

ParallelSystem strives to make the task of running in parallel simple, and effective.

It lets you define any number of commands, set max number of concurrent workers, set startup/finish hooks, and run the whole thing.

Final ->run() is blocking, and it (temporarily) sets CHLD signal handler to its own code, but it is reset to original value afterwards.

INTERNALS

new()

Object constructor. Takes one obligatory argument, and two optional:

max_jobs - obligatory integer, >= 1, defines how many workers to run at a time

on_start - coderef (anonymous sub for example) that will be called, every time new worker is spawned. There will be one argument to the code, and it will be job descriptor. More information about job descriptors in docs for add_command() method.

on_finish - coderef (anonymous sub for example) that will be called, every time worker finishes. There will be one argument to the code, and it will be job descriptor. More information about job descriptors in docs for add_command() method.

If there are problems with arguments (max_jobs not given, or bad, or hooks given, but not CODE refs - exception will be raised using Carp::croak().

Arguments are passed as hash - both hash and hashref are accepted, so you can both:

results()

Returns arrayref with all job descriptors (check add_command() method docs for details), after all the jobs have been ran.

add_command()

Adds new command to queue of things to be run.

Given argument (both hash and hashref are accepted) is treated as job descriptor.

To make the whole thing run, the only key needed is "command" - which should be arrayref of command and its arguments. The command cannot require any parsing - it will be passed directly to exec() syscall.

There can be more keys in the job descriptor, and all of them will be stored, and passed back in on_start/on_finish hooks, and will be present in ->results() data.

But, there will be several keys added by OmniPITR::Tools::ParallelSystem itself:

Available in all 3 places: on_start and on_finish hooks, and final ->results():

started - exact time when the worker has started. Time is as epoch time with microsecond precision.