Skip to content

Commit

Permalink
Merge pull request #102 from neighborhoods/master
Browse files Browse the repository at this point in the history
Merging common JSCLP-related code into 4.x
  • Loading branch information
mucha55 committed Jan 29, 2020
2 parents 51faf5c + 5450914 commit 7c96ccc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/Process/Pool/Strategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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].");
Expand Down Expand Up @@ -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()) {
Expand Down
4 changes: 3 additions & 1 deletion src/Process/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7c96ccc

Please sign in to comment.