From 230b34a1403350855d9ba65a992131f38683ff07 Mon Sep 17 00:00:00 2001 From: Gerhard Niemand Date: Sun, 6 Feb 2022 14:27:49 +0200 Subject: [PATCH 1/2] Have the processor keep running as long as both tick and the user callable are true --- src/SwarmProcess.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SwarmProcess.php b/src/SwarmProcess.php index 808442d..8a3cbd8 100644 --- a/src/SwarmProcess.php +++ b/src/SwarmProcess.php @@ -41,7 +41,7 @@ public function run(callable $moreWorkToAddCallable = null, callable $shouldCont } } - } while ($this->tick() || (is_callable($shouldContinueRunningCallable) ? call_user_func($shouldContinueRunningCallable) : false)); + } while ($this->tick() && (is_callable($shouldContinueRunningCallable) ? call_user_func($shouldContinueRunningCallable) : true)); } /** From f55ed857290ead18698f56114b11d771870455f4 Mon Sep 17 00:00:00 2001 From: Gerhard Niemand Date: Mon, 7 Feb 2022 06:44:02 +0200 Subject: [PATCH 2/2] Kill any remaining processes when done. Don't just exit and leave them orphaned --- src/SwarmProcess.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/SwarmProcess.php b/src/SwarmProcess.php index 8a3cbd8..d001ee0 100644 --- a/src/SwarmProcess.php +++ b/src/SwarmProcess.php @@ -42,6 +42,19 @@ public function run(callable $moreWorkToAddCallable = null, callable $shouldCont } } while ($this->tick() && (is_callable($shouldContinueRunningCallable) ? call_user_func($shouldContinueRunningCallable) : true)); + + + /** + * @var Process $runningProcess + */ + foreach ($this->currentRunningStack as $runningProcessKey => $runningProcess) { + if ($runningProcess->isRunning()) { + $runningProcess->stop(); + // do nothing, just log as checkTimeout() internally stops the process + $logMessage = '- Killed Process ' . $runningProcessKey . ' from currentRunningStack.'; + $this->logger->warning($logMessage); + } + } } /**