Skip to content

Commit db729ab

Browse files
committed
[Backport] Pull back updates to Deploy/Process/Queue made in 2.3-develop
1 parent 158f9a4 commit db729ab

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

app/code/Magento/Deploy/Process/Queue.php

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Deploy\Process;
79

810
use Magento\Deploy\Package\Package;
@@ -125,6 +127,8 @@ public function __construct(
125127
}
126128

127129
/**
130+
* Adds deployment package.
131+
*
128132
* @param Package $package
129133
* @param Package[] $dependencies
130134
* @return bool true on success
@@ -140,6 +144,8 @@ public function add(Package $package, array $dependencies = [])
140144
}
141145

142146
/**
147+
* Returns packages array.
148+
*
143149
* @return Package[]
144150
*/
145151
public function getPackages()
@@ -163,6 +169,7 @@ public function process()
163169
$this->assertAndExecute($name, $packages, $packageJob);
164170
}
165171
$this->logger->info('.');
172+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
166173
sleep(3);
167174
foreach ($this->inProgress as $name => $package) {
168175
if ($this->isDeployed($package)) {
@@ -183,8 +190,6 @@ public function process()
183190
* @param array $packages
184191
* @param array $packageJob
185192
* @return void
186-
*
187-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
188193
*/
189194
private function assertAndExecute($name, array & $packages, array $packageJob)
190195
{
@@ -208,13 +213,23 @@ private function assertAndExecute($name, array & $packages, array $packageJob)
208213
}
209214
}
210215
}
216+
$this->executePackage($package, $name, $packages, $dependenciesNotFinished);
217+
}
211218

219+
/**
220+
* Executes deployment package.
221+
*
222+
* @param Package $package
223+
* @param string $name
224+
* @param array $packages
225+
* @param bool $dependenciesNotFinished
226+
* @return void
227+
*/
228+
private function executePackage(Package $package, string $name, array &$packages, bool $dependenciesNotFinished)
229+
{
212230
if (!$dependenciesNotFinished
213231
&& !$this->isDeployed($package)
214-
&& (
215-
$this->maxProcesses < 2
216-
|| (count($this->inProgress) < $this->maxProcesses)
217-
)
232+
&& ($this->maxProcesses < 2 || (count($this->inProgress) < $this->maxProcesses))
218233
) {
219234
unset($packages[$name]);
220235
$this->execute($package);
@@ -235,6 +250,7 @@ private function awaitForAllProcesses()
235250
}
236251
}
237252
$this->logger->info('.');
253+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
238254
sleep(5);
239255
}
240256
if ($this->isCanBeParalleled()) {
@@ -244,6 +260,8 @@ private function awaitForAllProcesses()
244260
}
245261

246262
/**
263+
* Checks if can be parallel.
264+
*
247265
* @return bool
248266
*/
249267
private function isCanBeParalleled()
@@ -252,9 +270,10 @@ private function isCanBeParalleled()
252270
}
253271

254272
/**
273+
* Executes the process.
274+
*
255275
* @param Package $package
256276
* @return bool true on success for main process and exit for child process
257-
* @SuppressWarnings(PHPMD.ExitExpression)
258277
* @throws \RuntimeException
259278
*/
260279
private function execute(Package $package)
@@ -283,6 +302,7 @@ function () use ($package) {
283302
);
284303

285304
if ($this->isCanBeParalleled()) {
305+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
286306
$pid = pcntl_fork();
287307
if ($pid === -1) {
288308
throw new \RuntimeException('Unable to fork a new process');
@@ -297,6 +317,7 @@ function () use ($package) {
297317
// process child process
298318
$this->inProgress = [];
299319
$this->deployPackageService->deploy($package, $this->options, true);
320+
// phpcs:ignore Magento2.Security.LanguageConstruct.ExitUsage
300321
exit(0);
301322
} else {
302323
$this->deployPackageService->deploy($package, $this->options);
@@ -305,6 +326,8 @@ function () use ($package) {
305326
}
306327

307328
/**
329+
* Checks if package is deployed.
330+
*
308331
* @param Package $package
309332
* @return bool
310333
*/
@@ -320,6 +343,7 @@ private function isDeployed(Package $package)
320343
return false;
321344
}
322345

346+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
323347
$result = pcntl_waitpid($pid, $status, WNOHANG);
324348
if ($result === $pid) {
325349
$package->setState(Package::STATE_COMPLETED);
@@ -334,6 +358,7 @@ private function isDeployed(Package $package)
334358
);
335359

336360
unset($this->inProgress[$package->getPath()]);
361+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
337362
return pcntl_wexitstatus($status) === 0;
338363
} elseif ($result === -1) {
339364
$errno = pcntl_errno();
@@ -350,17 +375,19 @@ private function isDeployed(Package $package)
350375
}
351376

352377
/**
378+
* Returns process ID or null if not found.
379+
*
353380
* @param Package $package
354381
* @return int|null
355382
*/
356383
private function getPid(Package $package)
357384
{
358-
return isset($this->processIds[$package->getPath()])
359-
? $this->processIds[$package->getPath()]
360-
: null;
385+
return $this->processIds[$package->getPath()] ?? null;
361386
}
362387

363388
/**
389+
* Checks timeout.
390+
*
364391
* @return bool
365392
*/
366393
private function checkTimeout()
@@ -373,6 +400,7 @@ private function checkTimeout()
373400
*
374401
* Protect against zombie process
375402
*
403+
* @throws \RuntimeException
376404
* @return void
377405
*/
378406
public function __destruct()
@@ -387,6 +415,7 @@ public function __destruct()
387415
]
388416
);
389417

418+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
390419
if (pcntl_waitpid($pid, $status) === -1) {
391420
$errno = pcntl_errno();
392421
$strerror = pcntl_strerror($errno);

0 commit comments

Comments
 (0)