Skip to content

Commit 50dcc3d

Browse files
author
Stanislav Idolov
committed
1 parent 79d60cb commit 50dcc3d

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

app/code/Magento/Cron/Observer/ProcessCronQueueObserver.php

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ class ProcessCronQueueObserver implements ObserverInterface
138138
*/
139139
private $invalid = [];
140140

141-
/**
142-
* @var array
143-
*/
144-
private $jobs;
145-
146141
/**
147142
* @var Stat
148143
*/
@@ -389,7 +384,7 @@ private function getProfilingStat()
389384
*/
390385
private function getPendingSchedules($groupId)
391386
{
392-
$jobs = $this->getJobs();
387+
$jobs = $this->_config->getJobs();
393388
$pendingJobs = $this->_scheduleFactory->create()->getCollection();
394389
$pendingJobs->addFieldToFilter('status', Schedule::STATUS_PENDING);
395390
$pendingJobs->addFieldToFilter('job_code', ['in' => array_keys($jobs[$groupId])]);
@@ -437,7 +432,7 @@ private function generateSchedules($groupId)
437432
/**
438433
* generate global crontab jobs
439434
*/
440-
$jobs = $this->getJobs();
435+
$jobs = $this->_config->getJobs();
441436
$this->invalid = [];
442437
$this->_generateJobs($jobs[$groupId], $exists, $groupId);
443438
$this->cleanupScheduleMismatches();
@@ -500,11 +495,11 @@ private function cleanupJobs($groupId, $currentTime)
500495
Schedule::STATUS_PENDING => max($historyFailure, $historySuccess) * self::SECONDS_IN_MINUTE,
501496
];
502497

503-
$jobs = $this->getJobs()[$groupId];
498+
$jobs = $this->_config->getJobs()[$groupId];
504499
$scheduleResource = $this->_scheduleFactory->create()->getResource();
505500
$connection = $scheduleResource->getConnection();
506501
$count = 0;
507-
foreach ($historyLifetimes as $status => $time) {
502+
foreach ($historyLifetimes as $time) {
508503
$count += $connection->delete(
509504
$scheduleResource->getMainTable(),
510505
[
@@ -605,7 +600,7 @@ protected function getScheduleTimeInterval($groupId)
605600
*/
606601
private function cleanupDisabledJobs($groupId)
607602
{
608-
$jobs = $this->getJobs();
603+
$jobs = $this->_config->getJobs();
609604
$jobsToCleanup = [];
610605
foreach ($jobs[$groupId] as $jobCode => $jobConfig) {
611606
if (!$this->getCronExpression($jobConfig)) {
@@ -667,17 +662,6 @@ private function cleanupScheduleMismatches()
667662
return $this;
668663
}
669664

670-
/**
671-
* @return array
672-
*/
673-
private function getJobs()
674-
{
675-
if ($this->jobs === null) {
676-
$this->jobs = $this->_config->getJobs();
677-
}
678-
return $this->jobs;
679-
}
680-
681665
/**
682666
* Get CronGroup Configuration Value
683667
*
@@ -690,7 +674,6 @@ private function getCronGroupConfigurationValue($groupId, $path)
690674
'system/cron/' . $groupId . '/' . $path,
691675
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
692676
);
693-
return $scheduleLifetime;
694677
}
695678

696679
/**
@@ -737,20 +720,30 @@ private function processPendingJobs($groupId, $jobsRoot, $currentTime)
737720
$this->_runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId);
738721
}
739722
} catch (\Exception $e) {
740-
$schedule->setMessages($e->getMessage());
741-
if ($schedule->getStatus() === Schedule::STATUS_ERROR) {
742-
$this->logger->critical($e);
743-
}
744-
if ($schedule->getStatus() === Schedule::STATUS_MISSED
745-
&& $this->state->getMode() === State::MODE_DEVELOPER
746-
) {
747-
$this->logger->info($schedule->getMessages());
748-
}
723+
$this->processError($schedule, $e);
749724
}
750725
if ($schedule->getStatus() === Schedule::STATUS_SUCCESS) {
751726
$procesedJobs[$schedule->getJobCode()] = true;
752727
}
753728
$schedule->save();
754729
}
755730
}
731+
732+
/**
733+
* @param Schedule $schedule
734+
* @param \Exception $exception
735+
* @return void
736+
*/
737+
private function processError(\Magento\Cron\Model\Schedule $schedule, \Exception $exception)
738+
{
739+
$schedule->setMessages($exception->getMessage());
740+
if ($schedule->getStatus() === Schedule::STATUS_ERROR) {
741+
$this->logger->critical($exception);
742+
}
743+
if ($schedule->getStatus() === Schedule::STATUS_MISSED
744+
&& $this->state->getMode() === State::MODE_DEVELOPER
745+
) {
746+
$this->logger->info($schedule->getMessages());
747+
}
748+
}
756749
}

app/code/Magento/Cron/Test/Unit/Observer/ProcessCronQueueObserverTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,7 @@ public function testDispatchCanNotLock()
279279
public function testDispatchExceptionTooLate()
280280
{
281281
$exceptionMessage = 'Cron Job test_job1 is missed at 2017-07-30 15:00:00';
282-
$scheduleId = 42;
283282
$jobCode = 'test_job1';
284-
$exception = $exceptionMessage . ' Schedule Id: ' . $scheduleId . ' Job Code: ' . $jobCode;
285283

286284
$lastRun = $this->time + 10000000;
287285
$this->_cache->expects($this->any())->method('load')->willReturn($lastRun);

0 commit comments

Comments
 (0)