diff --git a/src/Process/Pool/Strategy.php b/src/Process/Pool/Strategy.php index 406c19d2..ac30df6a 100644 --- a/src/Process/Pool/Strategy.php +++ b/src/Process/Pool/Strategy.php @@ -21,7 +21,7 @@ public function childProcessExited(ProcessInterface $process): StrategyInterface } elseif ($process instanceof ListenerInterface) { $this->_listenerProcessExited($process); } elseif ($process instanceof JobStateChangelogProcessorInterface) { - // A new STL process will be created by the Root when appropriate + $this->_jobStateChangelogProcessorProcessExited($process); } else { $className = get_class($process); throw new \UnexpectedValueException("Unexpected process class[$className]."); @@ -98,6 +98,20 @@ protected function _jobProcessExited(JobInterface $jobProcess): Strategy return $this; } + protected function _jobStateChangelogProcessorProcessExited(JobStateChangelogProcessorInterface $jsclpProcess) : Strategy + { + $this->_getProcessPool()->freeChildProcess($jsclpProcess->getProcessId()); + + // usually this is where we'd spawn a new JSCLP to take the place of the one that exited, but + // that is handled by \Neighborhoods\Kojo\Process\Root::pollSingletonProcesses() + + if (!$this->_getProcessPool()->hasAlarm()) { + $this->_getProcessPool()->setAlarm($this->getMaxAlarmTime()); + } + + return $this; + } + public function receivedAlarm(): StrategyInterface { if (!$this->_getProcessPool()->isFull() && $this->_getProcessPool()->canEnvironmentSustainAdditionProcesses()) { diff --git a/src/Process/Root.php b/src/Process/Root.php index 41d65026..c5f08663 100644 --- a/src/Process/Root.php +++ b/src/Process/Root.php @@ -43,7 +43,9 @@ protected function pollSingletonProcesses() : Root if ($semaphoreResource->testLock()) { try { $process = $this->_getProcessCollection()->getProcessPrototypeClone($singletonType); - $this->_getProcessPool()->addChildProcess($process); + if (!$this->_getProcessPool()->isFull()) { + $this->_getProcessPool()->addChildProcess($process); + } } catch (Forked\Exception $forkedException) { // this is fine, another execution environment will spawn this process // TODO: consider breaking here to stop attempting to spawn other singletons