diff --git a/src/Process/Forked.php b/src/Process/Forked.php index 952f3295..6bf50d43 100644 --- a/src/Process/Forked.php +++ b/src/Process/Forked.php @@ -15,10 +15,14 @@ abstract class Forked extends ProcessAbstract implements ProcessInterface public function start(): ProcessInterface { $this->_create(self::PROP_HAS_FORKED, true); - $processId = $this->_getProcessStrategy()->fork(); - if ($processId === self::FORK_FAILURE_CODE) { - throw (new Exception())->setCode(Exception::CODE_FORK_FAILED); - } elseif ($processId > 0) { + try { + $processId = $this->_getProcessStrategy()->fork(); + } /** @noinspection PhpRedundantCatchClauseInspection */ + catch (\ErrorException $errorException) { + throw (new Exception())->setCode(Exception::CODE_FORK_FAILED)->setPrevious($errorException); + } + + if ($processId > 0) { // This is executed in the parent process. $this->_setProcessId($processId); } else { diff --git a/src/Process/Pool/Strategy.yml b/src/Process/Pool/Strategy.yml index afe3e4b0..b3c0df1c 100644 --- a/src/Process/Pool/Strategy.yml +++ b/src/Process/Pool/Strategy.yml @@ -16,8 +16,6 @@ services: shared: false class: Neighborhoods\Kojo\Process\Pool\Strategy\Server calls: - - [setAlarmProcessTypeCode, ['root']] - - [setFillProcessTypeCode, ['root']] - [setLogger, ['@process.pool.logger']] - [setMaximumLoadAverage, ['%process.pool.strategy-server.maximum_load_average%']] process.pool.strategy-server: diff --git a/src/Process/Pool/Strategy/Server.php b/src/Process/Pool/Strategy/Server.php index 8aaeab68..9e998dae 100644 --- a/src/Process/Pool/Strategy/Server.php +++ b/src/Process/Pool/Strategy/Server.php @@ -49,6 +49,7 @@ public function initializePool(): StrategyInterface $this->_getProcessPool()->addChildProcess($process); } catch (Exception $forkedException) { $this->_getLogger()->critical($forkedException->getMessage(), [(string)$forkedException]); + $this->_getProcessPool()->getProcess()->exit(); } } if ($this->_hasFillProcessTypeCode() && $this->_getProcessPool()->canEnvironmentSustainAdditionProcesses()) { diff --git a/src/Process/Strategy/ProcessControl.php b/src/Process/Strategy/ProcessControl.php index ccd6160e..a8709420 100644 --- a/src/Process/Strategy/ProcessControl.php +++ b/src/Process/Strategy/ProcessControl.php @@ -11,4 +11,4 @@ public function fork(): int { return pcntl_fork(); } -} \ No newline at end of file +} diff --git a/src/ProcessAbstract.php b/src/ProcessAbstract.php index 14a3de3b..f34186dd 100644 --- a/src/ProcessAbstract.php +++ b/src/ProcessAbstract.php @@ -98,6 +98,7 @@ public function exit(): void { $this->unregisterShutdownMethod(); $this->_getProcessPool()->terminateChildProcesses(); + $this->_getLogger()->debug("Exiting."); exit($this->_exitCode); } diff --git a/src/Runtime/ExceptionInterface.php b/src/Runtime/ExceptionInterface.php index f51bbd78..d6e01594 100644 --- a/src/Runtime/ExceptionInterface.php +++ b/src/Runtime/ExceptionInterface.php @@ -10,4 +10,8 @@ public function setCode(string $code): ExceptionInterface; public function addMessage(string $additionalMessage): ExceptionInterface; public function jsonSerialize(); + + public function setPrevious(\Throwable $previous): ExceptionInterface; + + public function addPossibleMessage(string $code, string $message): ExceptionInterface; }