From d39c0937c3c3ce065851fdb39a3b0175fd3bc024 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 6 Apr 2021 22:18:25 +0100 Subject: [PATCH 01/18] Produce success message only for humans --- app/code/Magento/Cron/Console/Command/CronCommand.php | 5 ++++- app/code/Magento/Cron/composer.json | 1 + app/code/Magento/Cron/etc/di.xml | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Cron/Console/Command/CronCommand.php b/app/code/Magento/Cron/Console/Command/CronCommand.php index 142a9a397eb5f..85a3d8243935d 100644 --- a/app/code/Magento/Cron/Console/Command/CronCommand.php +++ b/app/code/Magento/Cron/Console/Command/CronCommand.php @@ -115,6 +115,9 @@ protected function execute(InputInterface $input, OutputInterface $output) /** @var \Magento\Framework\App\Cron $cronObserver */ $cronObserver = $objectManager->create(\Magento\Framework\App\Cron::class, ['parameters' => $params]); $cronObserver->launch(); - $output->writeln('' . 'Ran jobs by schedule.' . ''); + + if (posix_isatty(STDOUT)) { + $output->writeln('' . 'Ran jobs by schedule.' . ''); + } } } diff --git a/app/code/Magento/Cron/composer.json b/app/code/Magento/Cron/composer.json index 00da35140744b..082681a67b94b 100644 --- a/app/code/Magento/Cron/composer.json +++ b/app/code/Magento/Cron/composer.json @@ -5,6 +5,7 @@ "sort-packages": true }, "require": { + "ext-posix": "*", "php": "~7.3.0||~7.4.0", "magento/framework": "*", "magento/module-store": "*" diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml index e7286169359bd..8beeea0af6f5e 100644 --- a/app/code/Magento/Cron/etc/di.xml +++ b/app/code/Magento/Cron/etc/di.xml @@ -65,7 +65,7 @@ - {magentoRoot}bin/magento cron:run | grep -v "Ran jobs by schedule" >> {magentoLog}magento.cron.log + {magentoRoot}bin/magento cron:run >> {magentoLog}magento.cron.log false From cd7c499f49de63a8a4d200150544766daf28ccc2 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 6 Apr 2021 22:44:43 +0100 Subject: [PATCH 02/18] Catch STDERR as well as STDOUT --- app/code/Magento/Cron/etc/di.xml | 2 +- .../Magento/Framework/Shell/CommandRendererBackground.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml index 8beeea0af6f5e..903ea478c4b60 100644 --- a/app/code/Magento/Cron/etc/di.xml +++ b/app/code/Magento/Cron/etc/di.xml @@ -65,7 +65,7 @@ - {magentoRoot}bin/magento cron:run >> {magentoLog}magento.cron.log + {magentoRoot}bin/magento cron:run >> {magentoLog}magento.cron.log 2>&1 false diff --git a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php index 5b61c62dae313..d77375debc502 100644 --- a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php +++ b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php @@ -35,6 +35,6 @@ public function render($command, array $arguments = []) return $this->osInfo->isWindows() ? 'start /B "magento background task" ' . $command - : str_replace('2>&1', '> /dev/null &', $command); + : str_replace('2>&1', '> /dev/null 2>&1 &', $command); } } From 0fe0e186adddb502d91982fe18cc9406a4a9bd0a Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 6 Apr 2021 23:05:04 +0100 Subject: [PATCH 03/18] Log output of background processes --- .../Observer/ProcessCronQueueObserver.php | 6 +++-- .../Shell/CommandRendererBackground.php | 23 ++++++++++++++++--- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php b/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php index 0f266b5d62d83..3c88f1d68bb24 100644 --- a/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php +++ b/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php @@ -254,10 +254,12 @@ function ($a, $b) { && $this->getCronGroupConfigurationValue($groupId, 'use_separate_process') == 1 ) { $this->_shell->execute( - $phpPath . ' %s cron:run --group=' . $groupId . ' --' . Cli::INPUT_KEY_BOOTSTRAP . '=' + '%s %s cron:run --group=%s --' . Cli::INPUT_KEY_BOOTSTRAP . '=' . self::STANDALONE_PROCESS_STARTED . '=1', [ - BP . '/bin/magento' + $phpPath, + BP . '/bin/magento', + $groupId, ] ); continue; diff --git a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php index d77375debc502..84f97320a0dab 100644 --- a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php +++ b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php @@ -5,20 +5,31 @@ */ namespace Magento\Framework\Shell; +use Magento\Framework\App\Filesystem\DirectoryList; +use Magento\Framework\Filesystem; use Magento\Framework\OsInfo; class CommandRendererBackground extends CommandRenderer { + /** + * @var Filesystem + */ + protected $filesystem; + /** * @var \Magento\Framework\OsInfo */ protected $osInfo; /** + * @param Filesystem $filesystem * @param OsInfo $osInfo */ - public function __construct(OsInfo $osInfo) - { + public function __construct( + Filesystem $filesystem, + OsInfo $osInfo + ) { + $this->filesystem = $filesystem; $this->osInfo = $osInfo; } @@ -33,8 +44,14 @@ public function render($command, array $arguments = []) { $command = parent::render($command, $arguments); + $logFile = '/dev/null'; + if ($groupId = $arguments[2] ?? null) { + $logDir = $this->filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); + $logFile = escapeshellarg($logDir . 'magento.cron.' . $groupId . '.log'); + } + return $this->osInfo->isWindows() ? 'start /B "magento background task" ' . $command - : str_replace('2>&1', '> /dev/null 2>&1 &', $command); + : str_replace('2>&1', ">> $logFile 2>&1 &", $command); } } From 0e2c0b8356c0ac3b1062df78e9634525450ff730 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 7 Apr 2021 22:31:42 +0100 Subject: [PATCH 04/18] Update test for new functionality --- .../Unit/CommandRendererBackgroundTest.php | 51 +++++++++++++++++-- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php index c737bc9c4461e..c83a064afae7f 100644 --- a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php +++ b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php @@ -7,6 +7,8 @@ namespace Magento\Framework\Shell\Test\Unit; +use Magento\Framework\Filesystem; +use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\OsInfo; use Magento\Framework\Shell\CommandRendererBackground; use PHPUnit\Framework\MockObject\MockObject; @@ -14,6 +16,13 @@ class CommandRendererBackgroundTest extends TestCase { + /** + * Test path to Magento's var/log directory + * + * @var string + */ + protected $logPath = '/path/to/magento/var/log/'; + /** * Test data for command * @@ -21,6 +30,11 @@ class CommandRendererBackgroundTest extends TestCase */ protected $testCommand = 'php -r test.php'; + /** + * @var Filesystem|MockObject + */ + protected $filesystem; + /** * @var OsInfo|MockObject */ @@ -30,23 +44,37 @@ protected function setUp(): void { $this->osInfo = $this->getMockBuilder(OsInfo::class) ->getMock(); + + $directoryMock = $this->getMockBuilder(ReadInterface::class) + ->getMock(); + $directoryMock->expects($this->any()) + ->method('getAbsolutePath') + ->willReturn($this->logPath); + + $this->filesystem = $this->getMockBuilder(Filesystem::class) + ->disableOriginalConstructor() + ->getMock(); + $this->filesystem->expects($this->any()) + ->method('getDirectoryRead') + ->willReturn($directoryMock); } /** * @dataProvider commandPerOsTypeDataProvider * @param bool $isWindows * @param string $expectedResults + * @param string[] $arguments */ - public function testRender($isWindows, $expectedResults) + public function testRender($isWindows, $expectedResults, $arguments) { $this->osInfo->expects($this->once()) ->method('isWindows') ->willReturn($isWindows); - $commandRenderer = new CommandRendererBackground($this->osInfo); + $commandRenderer = new CommandRendererBackground($this->filesystem, $this->osInfo); $this->assertEquals( $expectedResults, - $commandRenderer->render($this->testCommand) + $commandRenderer->render($this->testCommand, $arguments) ); } @@ -58,8 +86,21 @@ public function testRender($isWindows, $expectedResults) public function commandPerOsTypeDataProvider() { return [ - 'windows' => [true, 'start /B "magento background task" ' . $this->testCommand . ' 2>&1'], - 'unix' => [false, $this->testCommand . ' > /dev/null &'], + 'windows' => [ + true, + 'start /B "magento background task" ' . $this->testCommand . ' 2>&1', + [], + ], + 'unix-without-group-name' => [ + false, + $this->testCommand . ' >> /dev/null 2>&1 &', + [], + ], + 'unix-with-group-name' => [ + false, + $this->testCommand . " >> '{$this->logPath}magento.cron.group-name.log' 2>&1 &", + ['php-executable', 'script-path', 'group-name'], + ], ]; } } From 6e85c80b21a2886066e86f7d76e030226908575f Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 7 Apr 2021 22:32:12 +0100 Subject: [PATCH 05/18] Correct comment --- app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php b/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php index 3c88f1d68bb24..c747a7703ddce 100644 --- a/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php +++ b/app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php @@ -811,7 +811,7 @@ private function processPendingJobs(string $groupId, array $jobsRoot, int $curre /** @var Schedule $schedule */ foreach ($pendingJobs as $schedule) { if (isset($processedJobs[$schedule->getJobCode()])) { - // process only on job per run + // process only one of each job per run continue; } $jobConfig = isset($jobsRoot[$schedule->getJobCode()]) ? $jobsRoot[$schedule->getJobCode()] : null; From 42d783c7861099db7729a1aeaa401e54920bcba9 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 8 Apr 2021 18:50:34 +0100 Subject: [PATCH 06/18] Add ext-posix to root composer.json --- composer.json | 1 + composer.lock | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 276a9facfa1ad..46c15e11e7e8f 100644 --- a/composer.json +++ b/composer.json @@ -23,6 +23,7 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-pdo_mysql": "*", + "ext-posix": "*", "ext-simplexml": "*", "ext-soap": "*", "ext-xsl": "*", diff --git a/composer.lock b/composer.lock index 4295afd9ead7e..4a66e253901cf 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "9bc433740520119db84253a54d67a303", + "content-hash": "962083e98929e70d1ab0e3692a2e3a57", "packages": [ { "name": "aws/aws-sdk-php", @@ -11135,6 +11135,7 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-pdo_mysql": "*", + "ext-posix": "*", "ext-simplexml": "*", "ext-soap": "*", "ext-xsl": "*", From 365236a125d7f9fc35aa6f683dca3b8954a0fe3a Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 26 Apr 2023 13:22:53 +0100 Subject: [PATCH 07/18] Fix unit test failure --- .../Cron/Test/Unit/Console/Command/CronCommandTest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php b/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php index 83ebcddaf60b3..8718771432d0b 100644 --- a/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php +++ b/app/code/Magento/Cron/Test/Unit/Console/Command/CronCommandTest.php @@ -1,8 +1,10 @@ objectManagerFactory, $this->deploymentConfigMock) ); $commandTester->execute([]); - $expectedMsg = 'Ran jobs by schedule.' . PHP_EOL; + $expectedMsg = ''; $this->assertEquals($expectedMsg, $commandTester->getDisplay()); } } From a1d3859b6c2146b6fd24a818ae3f8b8ac1756a44 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 2 May 2023 13:39:20 +0100 Subject: [PATCH 08/18] Ignore intentional use of discouraged function --- app/code/Magento/Cron/Console/Command/CronCommand.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/code/Magento/Cron/Console/Command/CronCommand.php b/app/code/Magento/Cron/Console/Command/CronCommand.php index 321a8d3cdeef2..69e1630b7ce86 100644 --- a/app/code/Magento/Cron/Console/Command/CronCommand.php +++ b/app/code/Magento/Cron/Console/Command/CronCommand.php @@ -1,4 +1,5 @@ create(Cron::class, ['parameters' => $params]); $cronObserver->launch(); + // phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged if (posix_isatty(STDOUT)) { $output->writeln('' . 'Ran jobs by schedule.' . ''); } From 13bbeb1311251401e9af8641975fb2e96dccfbbd Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 10:51:34 +0100 Subject: [PATCH 09/18] Replace posix_isatty() with stream_isatty() --- app/code/Magento/Cron/Console/Command/CronCommand.php | 4 ++-- app/code/Magento/Cron/composer.json | 1 - composer.json | 1 - composer.lock | 3 +-- 4 files changed, 3 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Cron/Console/Command/CronCommand.php b/app/code/Magento/Cron/Console/Command/CronCommand.php index 69e1630b7ce86..ceb123724210f 100644 --- a/app/code/Magento/Cron/Console/Command/CronCommand.php +++ b/app/code/Magento/Cron/Console/Command/CronCommand.php @@ -141,8 +141,8 @@ protected function execute(InputInterface $input, OutputInterface $output) $cronObserver = $objectManager->create(Cron::class, ['parameters' => $params]); $cronObserver->launch(); - // phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged - if (posix_isatty(STDOUT)) { + // phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged,Magento2.Exceptions.TryProcessSystemResources.MissingTryCatch + if (stream_isatty(STDOUT)) { $output->writeln('' . 'Ran jobs by schedule.' . ''); } diff --git a/app/code/Magento/Cron/composer.json b/app/code/Magento/Cron/composer.json index f83c8c533ab78..1696588920015 100644 --- a/app/code/Magento/Cron/composer.json +++ b/app/code/Magento/Cron/composer.json @@ -5,7 +5,6 @@ "sort-packages": true }, "require": { - "ext-posix": "*", "php": "~8.1.0||~8.2.0", "magento/framework": "*", "magento/module-store": "*" diff --git a/composer.json b/composer.json index c2d0c4cfc5912..de82ab814e132 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,6 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-pdo_mysql": "*", - "ext-posix": "*", "ext-simplexml": "*", "ext-soap": "*", "ext-sodium": "*", diff --git a/composer.lock b/composer.lock index ee76b5d9b8c01..7cd9eaf2766f1 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "888e78f254ed1481460220ea3b4e86c2", + "content-hash": "0bc8161c0e1f3acf100e1fa3c445b1e2", "packages": [ { "name": "aws/aws-crt-php", @@ -14164,7 +14164,6 @@ "ext-mbstring": "*", "ext-openssl": "*", "ext-pdo_mysql": "*", - "ext-posix": "*", "ext-simplexml": "*", "ext-soap": "*", "ext-sodium": "*", From 17638f5b352cf6c7e8871d5aa7b0e9824911c7d1 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 11:16:18 +0100 Subject: [PATCH 10/18] Move Framework modifications into module --- .../Cron/Shell/CommandRendererBackground.php | 46 +++++++ .../Shell/CommandRendererBackgroundTest.php | 113 ++++++++++++++++++ app/code/Magento/Cron/etc/di.xml | 7 +- app/code/Magento/MessageQueue/etc/di.xml | 6 + .../Shell/CommandRendererBackground.php | 23 +--- .../Unit/CommandRendererBackgroundTest.php | 51 +------- 6 files changed, 176 insertions(+), 70 deletions(-) create mode 100644 app/code/Magento/Cron/Shell/CommandRendererBackground.php create mode 100644 app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php diff --git a/app/code/Magento/Cron/Shell/CommandRendererBackground.php b/app/code/Magento/Cron/Shell/CommandRendererBackground.php new file mode 100644 index 0000000000000..32196128980df --- /dev/null +++ b/app/code/Magento/Cron/Shell/CommandRendererBackground.php @@ -0,0 +1,46 @@ +filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); + $logFile = escapeshellarg($logDir . 'magento.cron.' . $groupId . '.log'); + } + + return $this->osInfo->isWindows() ? + 'start /B "magento background task" ' . $command + : str_replace('2>&1', ">> $logFile 2>&1 &", $command); + } +} diff --git a/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php b/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php new file mode 100644 index 0000000000000..bf6a7abf65423 --- /dev/null +++ b/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php @@ -0,0 +1,113 @@ +osInfo = $this->getMockBuilder(OsInfo::class) + ->getMock(); + + $directoryMock = $this->getMockBuilder(ReadInterface::class) + ->getMock(); + $directoryMock->expects($this->any()) + ->method('getAbsolutePath') + ->willReturn($this->logPath); + + $this->filesystem = $this->getMockBuilder(Filesystem::class) + ->disableOriginalConstructor() + ->getMock(); + $this->filesystem->expects($this->any()) + ->method('getDirectoryRead') + ->willReturn($directoryMock); + } + + /** + * @covers ::render + * @dataProvider commandPerOsTypeDataProvider + * + * @param bool $isWindows + * @param string $expectedResults + * @param string[] $arguments + */ + public function testRender($isWindows, $expectedResults, $arguments) + { + $this->osInfo->expects($this->once()) + ->method('isWindows') + ->willReturn($isWindows); + + $commandRenderer = new CommandRendererBackground($this->filesystem, $this->osInfo); + $this->assertEquals( + $expectedResults, + $commandRenderer->render($this->testCommand, $arguments) + ); + } + + /** + * Data provider for each os type + * + * @return array + */ + public function commandPerOsTypeDataProvider() + { + return [ + 'windows' => [ + true, + 'start /B "magento background task" ' . $this->testCommand . ' 2>&1', + [], + ], + 'unix-without-group-name' => [ + false, + $this->testCommand . ' >> /dev/null 2>&1 &', + [], + ], + 'unix-with-group-name' => [ + false, + $this->testCommand . " >> '{$this->logPath}magento.cron.group-name.log' 2>&1 &", + ['php-executable', 'script-path', 'group-name'], + ], + ]; + } +} diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml index 903ea478c4b60..73795e43a2640 100644 --- a/app/code/Magento/Cron/etc/di.xml +++ b/app/code/Magento/Cron/etc/di.xml @@ -28,15 +28,14 @@ - - + - Magento\Framework\Shell\CommandRendererBackground + Magento\Cron\Shell\CommandRendererBackground - shellBackground + shellBackgroundCron Magento\Cron\Model\VirtualLogger diff --git a/app/code/Magento/MessageQueue/etc/di.xml b/app/code/Magento/MessageQueue/etc/di.xml index caee6f7820c3b..7d4e4ca08b938 100644 --- a/app/code/Magento/MessageQueue/etc/di.xml +++ b/app/code/Magento/MessageQueue/etc/di.xml @@ -43,6 +43,12 @@ RefreshLock + + + + Magento\Framework\Shell\CommandRendererBackground + + shellBackground diff --git a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php index 84f97320a0dab..5b61c62dae313 100644 --- a/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php +++ b/lib/internal/Magento/Framework/Shell/CommandRendererBackground.php @@ -5,31 +5,20 @@ */ namespace Magento\Framework\Shell; -use Magento\Framework\App\Filesystem\DirectoryList; -use Magento\Framework\Filesystem; use Magento\Framework\OsInfo; class CommandRendererBackground extends CommandRenderer { - /** - * @var Filesystem - */ - protected $filesystem; - /** * @var \Magento\Framework\OsInfo */ protected $osInfo; /** - * @param Filesystem $filesystem * @param OsInfo $osInfo */ - public function __construct( - Filesystem $filesystem, - OsInfo $osInfo - ) { - $this->filesystem = $filesystem; + public function __construct(OsInfo $osInfo) + { $this->osInfo = $osInfo; } @@ -44,14 +33,8 @@ public function render($command, array $arguments = []) { $command = parent::render($command, $arguments); - $logFile = '/dev/null'; - if ($groupId = $arguments[2] ?? null) { - $logDir = $this->filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); - $logFile = escapeshellarg($logDir . 'magento.cron.' . $groupId . '.log'); - } - return $this->osInfo->isWindows() ? 'start /B "magento background task" ' . $command - : str_replace('2>&1', ">> $logFile 2>&1 &", $command); + : str_replace('2>&1', '> /dev/null &', $command); } } diff --git a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php index c83a064afae7f..c737bc9c4461e 100644 --- a/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php +++ b/lib/internal/Magento/Framework/Shell/Test/Unit/CommandRendererBackgroundTest.php @@ -7,8 +7,6 @@ namespace Magento\Framework\Shell\Test\Unit; -use Magento\Framework\Filesystem; -use Magento\Framework\Filesystem\Directory\ReadInterface; use Magento\Framework\OsInfo; use Magento\Framework\Shell\CommandRendererBackground; use PHPUnit\Framework\MockObject\MockObject; @@ -16,13 +14,6 @@ class CommandRendererBackgroundTest extends TestCase { - /** - * Test path to Magento's var/log directory - * - * @var string - */ - protected $logPath = '/path/to/magento/var/log/'; - /** * Test data for command * @@ -30,11 +21,6 @@ class CommandRendererBackgroundTest extends TestCase */ protected $testCommand = 'php -r test.php'; - /** - * @var Filesystem|MockObject - */ - protected $filesystem; - /** * @var OsInfo|MockObject */ @@ -44,37 +30,23 @@ protected function setUp(): void { $this->osInfo = $this->getMockBuilder(OsInfo::class) ->getMock(); - - $directoryMock = $this->getMockBuilder(ReadInterface::class) - ->getMock(); - $directoryMock->expects($this->any()) - ->method('getAbsolutePath') - ->willReturn($this->logPath); - - $this->filesystem = $this->getMockBuilder(Filesystem::class) - ->disableOriginalConstructor() - ->getMock(); - $this->filesystem->expects($this->any()) - ->method('getDirectoryRead') - ->willReturn($directoryMock); } /** * @dataProvider commandPerOsTypeDataProvider * @param bool $isWindows * @param string $expectedResults - * @param string[] $arguments */ - public function testRender($isWindows, $expectedResults, $arguments) + public function testRender($isWindows, $expectedResults) { $this->osInfo->expects($this->once()) ->method('isWindows') ->willReturn($isWindows); - $commandRenderer = new CommandRendererBackground($this->filesystem, $this->osInfo); + $commandRenderer = new CommandRendererBackground($this->osInfo); $this->assertEquals( $expectedResults, - $commandRenderer->render($this->testCommand, $arguments) + $commandRenderer->render($this->testCommand) ); } @@ -86,21 +58,8 @@ public function testRender($isWindows, $expectedResults, $arguments) public function commandPerOsTypeDataProvider() { return [ - 'windows' => [ - true, - 'start /B "magento background task" ' . $this->testCommand . ' 2>&1', - [], - ], - 'unix-without-group-name' => [ - false, - $this->testCommand . ' >> /dev/null 2>&1 &', - [], - ], - 'unix-with-group-name' => [ - false, - $this->testCommand . " >> '{$this->logPath}magento.cron.group-name.log' 2>&1 &", - ['php-executable', 'script-path', 'group-name'], - ], + 'windows' => [true, 'start /B "magento background task" ' . $this->testCommand . ' 2>&1'], + 'unix' => [false, $this->testCommand . ' > /dev/null &'], ]; } } From 485869e8c3c61a24bc6efbe79b77a1d3ecf520f1 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 11:22:44 +0100 Subject: [PATCH 11/18] Adhere to coding standard --- .../Magento/Cron/Shell/CommandRendererBackground.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Cron/Shell/CommandRendererBackground.php b/app/code/Magento/Cron/Shell/CommandRendererBackground.php index 32196128980df..c492531e1479f 100644 --- a/app/code/Magento/Cron/Shell/CommandRendererBackground.php +++ b/app/code/Magento/Cron/Shell/CommandRendererBackground.php @@ -1,8 +1,10 @@ filesystem->getDirectoryRead(DirectoryList::LOG)->getAbsolutePath(); + // @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged $logFile = escapeshellarg($logDir . 'magento.cron.' . $groupId . '.log'); } From 64df5bb62e5684d890e3bac0365dd115380a2d66 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 13:34:27 +0100 Subject: [PATCH 12/18] Correct namespace --- .../Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php b/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php index bf6a7abf65423..02358ca464069 100644 --- a/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php +++ b/app/code/Magento/Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php @@ -7,7 +7,7 @@ declare(strict_types=1); -namespace Magento\Cron\Shell\Test\Unit; +namespace Magento\Cron\Test\Unit\Shell; use Magento\Cron\Shell\CommandRendererBackground; use Magento\Framework\Filesystem; @@ -17,7 +17,7 @@ use PHPUnit\Framework\TestCase; /** - * @covers CommandRendererBackground + * @covers \Magento\Cron\Shell\CommandRendererBackground */ class CommandRendererBackgroundTest extends TestCase { From 8029ce9fb0cb774f47c9024a56cff67d45203404 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 16 May 2023 15:16:49 +0100 Subject: [PATCH 13/18] Add 'declare(strict_types=1);' --- app/code/Magento/Cron/Shell/CommandRendererBackground.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Cron/Shell/CommandRendererBackground.php b/app/code/Magento/Cron/Shell/CommandRendererBackground.php index c492531e1479f..b8f792b9c0a25 100644 --- a/app/code/Magento/Cron/Shell/CommandRendererBackground.php +++ b/app/code/Magento/Cron/Shell/CommandRendererBackground.php @@ -5,6 +5,8 @@ * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Cron\Shell; use Magento\Framework\App\Filesystem\DirectoryList; From 752821b64b13ea4f28abdef2869be8d9704bde3f Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 17 May 2023 10:53:16 +0100 Subject: [PATCH 14/18] Move global/api virtualType to app/etc/di.xml --- app/code/Magento/MessageQueue/etc/di.xml | 6 ------ app/etc/di.xml | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/MessageQueue/etc/di.xml b/app/code/Magento/MessageQueue/etc/di.xml index 7d4e4ca08b938..caee6f7820c3b 100644 --- a/app/code/Magento/MessageQueue/etc/di.xml +++ b/app/code/Magento/MessageQueue/etc/di.xml @@ -43,12 +43,6 @@ RefreshLock - - - - Magento\Framework\Shell\CommandRendererBackground - - shellBackground diff --git a/app/etc/di.xml b/app/etc/di.xml index c74ce0d679439..19bcc8a875cb9 100644 --- a/app/etc/di.xml +++ b/app/etc/di.xml @@ -2008,4 +2008,10 @@ + + + + Magento\Framework\Shell\CommandRendererBackground + + From e44ac4885e52c2d51cf7d2c73499dcd4e51180fd Mon Sep 17 00:00:00 2001 From: engcom-Charlie Date: Wed, 24 May 2023 16:30:06 +0530 Subject: [PATCH 15/18] Draft:Increase the page load time --- ...ontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml index e5f464920c3ee..62d53b6adb706 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml @@ -83,7 +83,7 @@ - + From 3925deb7520d76dc815bfdef5d696deb32b88e87 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 24 May 2023 15:19:50 +0100 Subject: [PATCH 16/18] Revert "Draft:Increase the page load time" This reverts commit e44ac4885e52c2d51cf7d2c73499dcd4e51180fd. --- ...ontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml index 62d53b6adb706..e5f464920c3ee 100644 --- a/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml +++ b/app/code/Magento/Catalog/Test/Mftf/Test/StorefrontVerifyProductAfterPartialReindexOnSeveralWebsitesTest.xml @@ -83,7 +83,7 @@ - + From 9886e2385d3c80b1612d541cecdadae57a1fb689 Mon Sep 17 00:00:00 2001 From: Indrani Sonawane Date: Fri, 22 Nov 2024 14:54:38 +0530 Subject: [PATCH 17/18] Fixed Static test failures --- app/code/Magento/Cron/Console/Command/CronCommand.php | 4 ++-- app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php | 4 ++-- app/code/Magento/Cron/Shell/CommandRendererBackground.php | 4 ++-- .../Cron/Test/Unit/Console/Command/CronCommandTest.php | 4 ++-- .../Cron/Test/Unit/Shell/CommandRendererBackgroundTest.php | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Cron/Console/Command/CronCommand.php b/app/code/Magento/Cron/Console/Command/CronCommand.php index ceb123724210f..4e8c4ea1a4404 100644 --- a/app/code/Magento/Cron/Console/Command/CronCommand.php +++ b/app/code/Magento/Cron/Console/Command/CronCommand.php @@ -1,8 +1,8 @@ Date: Fri, 22 Nov 2024 18:27:12 +0530 Subject: [PATCH 18/18] Fixed Static test --- app/code/Magento/Cron/etc/di.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Cron/etc/di.xml b/app/code/Magento/Cron/etc/di.xml index 73795e43a2640..bcb11691753d6 100644 --- a/app/code/Magento/Cron/etc/di.xml +++ b/app/code/Magento/Cron/etc/di.xml @@ -1,8 +1,8 @@