StoreProcess
- Placeholder class for executing a process, manipulating the process and logging its output.
use Parameter::Group;
use SmartLog;
use StoreProcess;
# create a Parameter-instance
my $c=Parameter::Group->new();
# instantiate
my $sp=StoreProcess->new(pars=>$c);
# execute StoreProcess
$sp->execute();
# get log instance of the StoreProcess
my $log=$sp->getlog();
# reset pointer to where reading log
$log->resetNext();
# output log while StoreProcess is running
while ($sp->isrunning()) {
print "".$log->getnext()."\n";
}
Placeholder class for executing a process, manipulating the process and logging its output.
It makes it possible to execute a process while the output of that process is being logged. It handles the return exitcode of the process, stop or cease the execution of that process and so on.
This class is not meant to be instantiated, but inherited.
Instantiates the class.
Valid parameters are:
pars Sets the Parameter::Group-class instance for the StoreProcess. Required. Will default to an empty Parameter::Group-class instance if not specified.
timeout Sets the timeout of the command being executed by the StoreProcess. It is specified in seconds, where 0 is never. Optional and if not specified will default to 0.
wait Sets the wait time for the command being executed by the StoreProcess. It is specified in seconds, where 0 is forever. Optional and will default to 0.
Returns the StoreProcess-instance
Executes the StoreProcess command (see the pars-option in the new()-method).
The method accepts no input.
It will attempt to execute the command that the StoreProcess is meant to run, fork a process to handle logging its output back to the parent StoreProcess. It will check timeout- and wait-values (see the new()-methods options).
The method will return 1 upon successful start of execution, 0 upon failure. Please check the error()-method for more information upon failure.
Setups- and starts the process to be executed.
No input is accepted and it returns 1.
This method is internal and meant to be overridden by the inheriting class. It is not to be called by the user.
Performs cleanup if the StoreProcess after the fork'ed child process exits.
It takes no input.
Always returns 1.
This method is internal and meant to be overridden by the inheriting class. It is not to be called by the user.
Update the progress of the fork'ed child process in the log.
It reads the output handler from the fork'ed child process and add's the output to the log-instance of the StoreProcess class. It also updates the alive-timestamp for when it last saw output from the child process.
It will also harvest the exitcode from the process and it expects it to be 0 upon success and the result of this also marks the overall success of the StoreProcess execution itself (see the success()-method).
Returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.
Gets the log instance of the StoreProcess-class.
No input accepted.
Returns the log-instance of the StoreProcess-class.
Resets the log instance of the StoreProcess-class.
It will only accept resetting the log if no StoreProcess is running and the read handle from the fork'ed child process has been emptied.
Returns 1 upon success, 0 upon failure. Please check the error()-method for more information upon failure.
Sets or gets the timeout value of the StoreProcess command.
On get, it takes no input. On set, it takes the value of the timeout.
Timeout value is given in seconds to wait on any change/update in the output from the fork'ed child process being run. 0 means it will never timeout.
On get the return value is the timeout value. On set, the return value is 1.
Also see the timeout-option in the new()-method for more information.
Sets or gets the wait time value of the StoreProcess command.
On get, it takes no input. On set, it takes the value of the wait time.
Wait value is given in seconds to wait on the fork'ed child process finishing, independant of any timeout or any change/update in the output from it. 0 means it will wait forever.
On get the return value is the wait value. On set, the return value is 1.
Also see the wait-option in the new()-method for more information.
Checks to see if the store-process is still running and updating the StoreProcess output log at the same time.
Method accepts no input.
Returns 1 if running, 0 if not.
Checks to see if the StoreProcess read-handle on the fork'ed child process has been emptied or not.
Method accepts no input.
Returns 1 if emptied, 0 if not.
Returns the last timestamp from getting new output from the StoreProcess command.
Returns the exitcode from a finished executed StoreProcess-command.
Returns the exitcode upon success, undef upon failure. Please check the error()-method for more information upon error.
Cease or stop the StoreProcess being executed.
It takes no input.
It does this by killing the fork'ed child process.
Returns 1 upon success, 0 upon failure. Please check the error()-method upon failure.
Placeholder method that performs child specific stopping/ceasing of the StoreProcess being executed.
This method is called by the cease()-method and is internal and not meant to be called by the user.
The method is to be overridden by the inheriting class.
Returns 1 upon success, 0 upon failure.
Returns the success of the last StoreProcess execution.
It requires that a process has been executed and ended.
Returns 1 upon success, 0 upon failure.
Returns the pid of the process reading the log filehandler of StoreProcess.
No input is accepted.
It returns either the PID upon success, or 0 upon failure (no process running).
Returns the last error message of the instance.
Accepts no input.
Returns the last error message as a SCALAR.