コード例 #1
0
ファイル: Observer.php プロジェクト: aiesh/magento2
 /**
  * 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);
     }
 }
コード例 #2
0
 /**
  * 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);
     }
 }
コード例 #3
0
ファイル: Observer.php プロジェクト: shabbirvividads/magento2
 /**
  * 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);
     }
 }