Thanks to visit codestin.com
Credit goes to github.com

Skip to content

AC-9270: Add Optional --force-use-same-process Parameter to Cron:Run Cli Command #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 2 additions & 77 deletions src/Magento/FunctionalTestingFramework/Module/MagentoWebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class MagentoWebDriver extends WebDriver
pause as codeceptPause;
}

const MAGENTO_CRON_INTERVAL = 60;
const MAGENTO_CRON_COMMAND = 'cron:run';

/**
Expand Down Expand Up @@ -118,13 +117,6 @@ class MagentoWebDriver extends WebDriver
*/
private $jsErrors = [];

/**
* Contains last execution times for Cron
*
* @var int[]
*/
private $cronExecution = [];

/**
* Sanitizes config, then initializes using parent.
*
Expand Down Expand Up @@ -584,65 +576,6 @@ public function magentoCron($cronGroups = null, $timeout = null, $arguments = nu
return $this->executeCronjobs($cronGroups, $timeout, $arguments);
}

/**
* Updates last execution time for Cron
*
* @param array $cronGroups
* @return void
*/
private function notifyCronFinished(array $cronGroups = [])
{
if (empty($cronGroups)) {
$this->cronExecution['*'] = time();
}

foreach ($cronGroups as $group) {
$this->cronExecution[$group] = time();
}
}

/**
* Returns last Cron execution time for specific cron or all crons
*
* @param array $cronGroups
* @return integer
*/
private function getLastCronExecution(array $cronGroups = [])
{
if (empty($this->cronExecution)) {
return 0;
}

if (empty($cronGroups)) {
return (int)max($this->cronExecution);
}

$cronGroups = array_merge($cronGroups, ['*']);

return array_reduce($cronGroups, function ($lastExecution, $group) {
if (isset($this->cronExecution[$group]) && $this->cronExecution[$group] > $lastExecution) {
$lastExecution = $this->cronExecution[$group];
}

return (int)$lastExecution;
}, 0);
}

/**
* Returns time to wait for next run
*
* @param array $cronGroups
* @param integer $cronInterval
* @return integer
*/
private function getCronWait(array $cronGroups = [], int $cronInterval = self::MAGENTO_CRON_INTERVAL)
{
$nextRun = $this->getLastCronExecution($cronGroups) + $cronInterval;
$toNextRun = $nextRun - time();

return max(0, $toNextRun);
}

/**
* Runs DELETE request to delete a Magento entity against the url given.
*
Expand Down Expand Up @@ -1021,8 +954,6 @@ public function getOTP($secretsPath = null)
}

/**
* Waits proper amount of time to perform Cron execution
*
* @param array $cronGroups
* @param integer $timeout
* @param string $arguments
Expand All @@ -1037,11 +968,7 @@ private function executeCronjobs($cronGroups, $timeout, $arguments): string
$arguments .= ' --bootstrap=standaloneProcessStarted=1';
}

$waitFor = $this->getCronWait($cronGroups);

if ($waitFor) {
$this->wait($waitFor);
}
$arguments .= ' --force-use-same-process'; // Execute cron jobs in one process

$command = array_reduce($cronGroups, function ($command, $cronGroup) {
$command .= ' --group=' . $cronGroup;
Expand All @@ -1051,9 +978,7 @@ private function executeCronjobs($cronGroups, $timeout, $arguments): string
$cronResult = $this->magentoCLI($command, $timeout, $arguments);
$timeEnd = microtime(true);

$this->notifyCronFinished($cronGroups);

return sprintf('%s (wait: %ss, execution: %ss)', $cronResult, $waitFor, round($timeEnd - $timeStart, 2));
return sprintf('%s (execution: %ss)', $cronResult, round($timeEnd - $timeStart, 2));
}

/**
Expand Down