|
10 | 10 | use Magento\Deploy\Package\Package;
|
11 | 11 | use Magento\Deploy\Service\DeployPackage;
|
12 | 12 | use Magento\Framework\App\ResourceConnection;
|
13 |
| -use Psr\Log\LoggerInterface; |
14 | 13 | use Magento\Framework\App\State as AppState;
|
15 | 14 | use Magento\Framework\Locale\ResolverInterface as LocaleResolver;
|
| 15 | +use Psr\Log\LoggerInterface; |
16 | 16 |
|
17 | 17 | /**
|
18 | 18 | * Deployment Queue
|
@@ -165,6 +165,7 @@ public function process()
|
165 | 165 | $packages = $this->packages;
|
166 | 166 | while (count($packages) && $this->checkTimeout()) {
|
167 | 167 | foreach ($packages as $name => $packageJob) {
|
| 168 | + // Unsets each member of $packages array (passed by reference) as each is executed |
168 | 169 | $this->assertAndExecute($name, $packages, $packageJob);
|
169 | 170 | }
|
170 | 171 | $this->logger->info('.');
|
@@ -224,12 +225,8 @@ private function assertAndExecute($name, array & $packages, array $packageJob)
|
224 | 225 | * @param bool $dependenciesNotFinished
|
225 | 226 | * @return void
|
226 | 227 | */
|
227 |
| - private function executePackage( |
228 |
| - Package $package, |
229 |
| - string $name, |
230 |
| - array &$packages, |
231 |
| - bool $dependenciesNotFinished |
232 |
| - ) { |
| 228 | + private function executePackage(Package $package, string $name, array &$packages, bool $dependenciesNotFinished) |
| 229 | + { |
233 | 230 | if (!$dependenciesNotFinished
|
234 | 231 | && !$this->isDeployed($package)
|
235 | 232 | && ($this->maxProcesses < 2 || (count($this->inProgress) < $this->maxProcesses))
|
@@ -339,13 +336,29 @@ private function isDeployed(Package $package)
|
339 | 336 | if ($this->isCanBeParalleled()) {
|
340 | 337 | if ($package->getState() === null) {
|
341 | 338 | // phpcs:ignore Magento2.Functions.DiscouragedFunction
|
342 |
| - $pid = pcntl_waitpid($this->getPid($package), $status, WNOHANG); |
343 |
| - if ($pid === $this->getPid($package)) { |
| 339 | + $result = pcntl_waitpid($pid, $status, WNOHANG); |
| 340 | + if ($result === $pid) { |
344 | 341 | $package->setState(Package::STATE_COMPLETED);
|
| 342 | + $exitStatus = pcntl_wexitstatus($status); |
| 343 | + |
| 344 | + $this->logger->info( |
| 345 | + "Exited: " . $package->getPath() . "(status: $exitStatus)", |
| 346 | + [ |
| 347 | + 'process' => $package->getPath(), |
| 348 | + 'status' => $exitStatus, |
| 349 | + ] |
| 350 | + ); |
345 | 351 |
|
346 | 352 | unset($this->inProgress[$package->getPath()]);
|
347 | 353 | // phpcs:ignore Magento2.Functions.DiscouragedFunction
|
348 | 354 | return pcntl_wexitstatus($status) === 0;
|
| 355 | + } elseif ($result === -1) { |
| 356 | + $errno = pcntl_errno(); |
| 357 | + $strerror = pcntl_strerror($errno); |
| 358 | + |
| 359 | + throw new \RuntimeException( |
| 360 | + "Error encountered checking child process status (PID: $pid): $strerror (errno: $errno)" |
| 361 | + ); |
349 | 362 | }
|
350 | 363 | return false;
|
351 | 364 | }
|
@@ -385,10 +398,22 @@ private function checkTimeout()
|
385 | 398 | public function __destruct()
|
386 | 399 | {
|
387 | 400 | foreach ($this->inProgress as $package) {
|
| 401 | + $pid = $this->getPid($package); |
| 402 | + $this->logger->info( |
| 403 | + "Reaping child process: {$package->getPath()} (PID: $pid)", |
| 404 | + [ |
| 405 | + 'process' => $package->getPath(), |
| 406 | + 'pid' => $pid, |
| 407 | + ] |
| 408 | + ); |
| 409 | + |
388 | 410 | // phpcs:ignore Magento2.Functions.DiscouragedFunction
|
389 |
| - if (pcntl_waitpid($this->getPid($package), $status) === -1) { |
| 411 | + if (pcntl_waitpid($pid, $status) === -1) { |
| 412 | + $errno = pcntl_errno(); |
| 413 | + $strerror = pcntl_strerror($errno); |
| 414 | + |
390 | 415 | throw new \RuntimeException(
|
391 |
| - 'Error while waiting for package deployed: ' . $this->getPid($package) . '; Status: ' . $status |
| 416 | + "Error encountered waiting for child process (PID: $pid): $strerror (errno: $errno)" |
392 | 417 | );
|
393 | 418 | }
|
394 | 419 | }
|
|
0 commit comments