From e79de7253d85f65aed961491ce489bf46f6e9755 Mon Sep 17 00:00:00 2001 From: Danko Adamczyk Date: Mon, 30 Sep 2019 17:02:07 +0200 Subject: [PATCH] Do not break when there are still running jobs. --- Command/RunCommand.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Command/RunCommand.php b/Command/RunCommand.php index 98898c1f..053d1135 100644 --- a/Command/RunCommand.php +++ b/Command/RunCommand.php @@ -173,15 +173,20 @@ private function runJobs($workerName, $startTime, $maxRuntime, $idleTime, $maxJo pcntl_signal_dispatch(); } - if ($this->shouldShutdown || time() - $startTime > $maxRuntime) { + $this->checkRunningJobs(); + + $shouldShutdown = $this->shouldShutdown || time() - $startTime > $maxRuntime; + + if($shouldShutdown === true && empty($this->runningJobs)){ break; } - $this->checkRunningJobs(); - $this->startJobs($workerName, $idleTime, $maxJobs, $restrictedQueues, $queueOptionsDefaults, $queueOptions); + if($shouldShutdown === false){ + $this->startJobs($workerName, $idleTime, $maxJobs, $restrictedQueues, $queueOptionsDefaults, $queueOptions); + } $waitTimeInMs = random_int(500, 1000); - usleep($waitTimeInMs * 1E3); + usleep((int) ($waitTimeInMs * 1E3)); } if ($this->verbose) {