/** * Process cron queue * Generate tasks schedule * Cleanup tasks schedule * * @param \Magento\Framework\Event\Observer $observer * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function execute(\Magento\Framework\Event\Observer $observer) { $pendingJobs = $this->_getPendingSchedules(); $currentTime = $this->timezone->scopeTimeStamp(); $jobGroupsRoot = $this->_config->getJobs(); foreach ($jobGroupsRoot as $groupId => $jobsRoot) { if ($this->_request->getParam('group') !== null && $this->_request->getParam('group') !== '\'' . $groupId . '\'' && $this->_request->getParam('group') !== $groupId) { continue; } if ($this->_request->getParam(self::STANDALONE_PROCESS_STARTED) !== '1' && $this->_scopeConfig->getValue('system/cron/' . $groupId . '/use_separate_process', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) == 1) { $this->_shell->execute('php %s cron:run --group=' . $groupId . ' --' . CLI::INPUT_KEY_BOOTSTRAP . '=' . self::STANDALONE_PROCESS_STARTED . '=1', [BP . '/bin/magento']); continue; } foreach ($pendingJobs as $schedule) { $jobConfig = isset($jobsRoot[$schedule->getJobCode()]) ? $jobsRoot[$schedule->getJobCode()] : null; if (!$jobConfig) { continue; } $scheduledTime = strtotime($schedule->getScheduledAt()); if ($scheduledTime > $currentTime) { continue; } try { if ($schedule->tryLockJob()) { $this->_runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId); } } catch (\Exception $e) { $schedule->setMessages($e->getMessage()); } $schedule->save(); } $this->_generate($groupId); $this->_cleanup($groupId); } }
/** * Process cron queue * Generate tasks schedule * Cleanup tasks schedule * * @param \Magento\Framework\Event\Observer $observer * @return void */ public function dispatch($observer) { $pendingJobs = $this->_getPendingSchedules(); $currentTime = time(); $jobGroupsRoot = $this->_config->getJobs(); foreach ($jobGroupsRoot as $groupId => $jobsRoot) { if ($this->_request->getParam('group') === null && $this->_scopeConfig->getValue('system/cron/' . $groupId . '/use_separate_process', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) == 1) { $this->_shell->execute('%s -f %s -- --group=%s', array(PHP_BINARY, BP . '/' . \Magento\Framework\App\Filesystem::PUB_DIR . '/cron.php', $groupId)); continue; } if ($this->_request->getParam('group') !== null && $this->_request->getParam('group') != $groupId) { continue; } foreach ($pendingJobs as $schedule) { $jobConfig = isset($jobsRoot[$schedule->getJobCode()]) ? $jobsRoot[$schedule->getJobCode()] : null; if (!$jobConfig) { continue; } $scheduledTime = strtotime($schedule->getScheduledAt()); if ($scheduledTime > $currentTime || !$schedule->tryLockJob()) { continue; } try { $this->_runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId); } catch (\Exception $e) { $schedule->setMessages($e->getMessage()); } $schedule->save(); } $this->_generate($groupId); $this->_cleanup($groupId); } }
/** * Process cron queue * Generate tasks schedule * Cleanup tasks schedule * * @param \Magento\Framework\Event\Observer $observer * @return void * @SuppressWarnings(PHPMD.CyclomaticComplexity) * @SuppressWarnings(PHPMD.NPathComplexity) * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ public function dispatch($observer) { $pendingJobs = $this->_getPendingSchedules(); $currentTime = $this->timezone->scopeTimeStamp(); $jobGroupsRoot = $this->_config->getJobs(); foreach ($jobGroupsRoot as $groupId => $jobsRoot) { if ($this->_request->getParam('group') !== null && $this->_request->getParam('group') != $groupId) { continue; } if ($this->_request->getParam('standaloneProcessStarted') !== '1' && $this->_scopeConfig->getValue('system/cron/' . $groupId . '/use_separate_process', \Magento\Store\Model\ScopeInterface::SCOPE_STORE) == 1) { $this->_shell->execute('php -f %s -- --group=%s --standaloneProcessStarted=%s', [BP . '/' . DirectoryList::PUB . '/cron.php', $groupId, '1']); continue; } foreach ($pendingJobs as $schedule) { $jobConfig = isset($jobsRoot[$schedule->getJobCode()]) ? $jobsRoot[$schedule->getJobCode()] : null; if (!$jobConfig) { continue; } $scheduledTime = strtotime($schedule->getScheduledAt()); if ($scheduledTime > $currentTime) { continue; } try { if ($schedule->tryLockJob()) { $this->_runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId); } } catch (\Exception $e) { $schedule->setMessages($e->getMessage()); } $schedule->save(); } $this->_generate($groupId); $this->_cleanup($groupId); } }
public function testRegenerateStatic() { $storeLocales = ['fr_FR', 'de_DE', 'nl_NL']; $adminUserInterfaceLocales = ['de_DE', 'en_US']; $this->storeViewMock->expects($this->once())->method('retrieveLocales')->willReturn($storeLocales); $userMock = $this->getMock(\Magento\User\Model\User::class, [], [], '', false); $userMock->expects($this->once())->method('getInterfaceLocale')->willReturn('en_US'); $this->userCollectionMock->expects($this->once())->method('getIterator')->willReturn(new \ArrayIterator([$userMock])); $usedLocales = array_unique(array_merge($storeLocales, $adminUserInterfaceLocales)); $staticContentDeployCmd = $this->cmdPrefix . 'setup:static-content:deploy ' . implode(' ', $usedLocales); $setupDiCompileCmd = $this->cmdPrefix . 'setup:di:compile'; $this->shellMock->expects($this->at(0))->method('execute')->with($staticContentDeployCmd); $this->shellMock->expects($this->at(1))->method('execute')->with($setupDiCompileCmd); $this->outputMock->expects($this->at(0))->method('writeln')->with('Starting deployment of static content'); $this->outputMock->expects($this->at(2))->method('writeln')->with('Deployment of static content complete'); $this->outputMock->expects($this->at(3))->method('writeln')->with('Starting compilation'); $this->outputMock->expects($this->at(5))->method('writeln')->with('Compilation complete'); $this->filesystem->regenerateStatic($this->outputMock); }
/** * Runs compiler * * @param OutputInterface $output * @return void * @throws LocalizedException */ protected function compile(OutputInterface $output) { $output->writeln('Starting compilation'); $this->cleanupFilesystem([DirectoryList::CACHE, DirectoryList::GENERATION, DirectoryList::DI]); $cmd = $this->functionCallPath . 'setup:di:compile'; /** * exec command is necessary for now to isolate the autoloaders in the compiler from the memory state * of this process, which would prevent some classes from being generated * * @todo eliminate exec */ try { $execOutput = $this->shell->execute($cmd); } catch (LocalizedException $e) { $output->writeln('Something went wrong while compiling generated code. See the error log for details.'); throw $e; } $output->writeln($execOutput); $output->writeln('Compilation complete'); }