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

Process::SubProcess::Group - Module to manage and run multiple Sub Processes at once

DESCRIPTION

Process::SubProcess::Group implements a class to manage multiple Sub Process and run them at once while keeping their Output and Errors related to each command.

The Idea of this API is to launch Sub Processes and keep track of all Output on STDOUT, STDERR, the EXIT CODE and possible System Errors at Launch Time in an object oriented manner.

METHODS

Constructor

new ( [ CONFIGURATIONS ] )

This is the constructor for a new SubProcess.

Parameters:

CONFIGURATIONS are passed in a hash like fashion, using key and value pairs.

Recognized Configurations:

check - Time in seconds when to check a process for new output. This is calculated based on the count of processes to manage.

read | readtimeout - Time in seconds to wait for the process output. If the process is expected to run longer it is useful to set it to avoid excessive checks. It is also important for multiple process execusions, because other processes will not be checked before the read has not timed out.

timeout - Time in seconds to wait for the process to finish. After this time the process will be terminated

debug - show internal processing information

quiet - do not print any warnings or errors

Administration Methods

add ( [ OBJECT | CLASS ] )

This method adds a Process object to the list of managed processes.

Parameters:

OBJECT | CLASS - is a Process::SubProcess object or a compatible class name. If a class name or no parameter is given a new object will be created.

Returns: It returns the object that was addded to list. If an object was given the same will be returned.

See Method Process::SubProcess::setArrProcess()

setCheckInterval ( INTERVAL )

This method calculates the READTIMEOUT for each Process::SubProcess object according to the amount of existing objects. The value of the READTIMEOUT for each Process will be rounded to a whole number.

Example:

The Process Group manages 3 Processes. Processes "A", "B" and "C". Process "A" should be checked every 6 seconds. So, setting setCheckInterval(6) will set the READTIMEOUT of Processes "A", "B" and "C" to 2 seconds. This way after cycling over the processes the Process "A" will be checked again after 6 seconds.

Parameters:

INTERVAL - is an integer that specifies the interval in which all processes should be checked once.

See Method Process::SubProcess::setReadTimeout()

setReadTimeout ( TIMEOUT )

This method set the READTIMEOUT for each Process::SubProcess object.

Parameters:

TIMEOUT - is an integer that specifies the time in seconds to wait for output from the command for each Process::SubProcess object.

See Method Process::SubProcess::setReadTimeout()

setTimeout ( TIMEOUT )

This method set the EXECUTIONTIMEOUT for the Process::SubProcess::Group object.

This enables the EXECUTIONTIMEOUT functionality in the Wait() method which ensures that no process runs longer than required. The Wait() method will call the Terminate() method which will call the Terminate() method on each Process::SubProcess that is still running.

Parameters:

TIMEOUT - is an integer that specifies the maximal execution time in seconds of the whole Process Group execution.

See Method Wait()

Wait ( [ CONFIGURATIONS ] )

This method checks the Process::SubProcess objects regularly and continues until all Process::SubProcess objects report that they are not RUNNING anymore.

If the EXECUTIONTIMEOUT functionality is enabled the method will call the Terminate() method which then calls the Terminate() method on each Process::SubProcess that is still running.

Parameters:

CONFIGURATIONS - is a list are passed in a hash like fashion, using key and value pairs.

Recognized Configurations:

check - is an integer that specifies the interval in which all processes should be checked once.

read | readtimeout - is an integer that specifies the time in seconds to wait for output from the command for each Process::SubProcess object.

timeout - is an integer that specifies the maximal execution time in seconds of the whole Process Group execution.

See Method Process::SubProcess::Terminate()

See Method setCheckInterval()

See Method setReadTimeout()

See Method setTimeout()