Skip to content

Commit b38336c

Browse files
author
Bohdan Korablov
committed
MAGETWO-94369 [Forwardport] Move cron improvements from 2.2 to 2.3
1 parent efeda8d commit b38336c

File tree

2 files changed

+43
-18
lines changed

2 files changed

+43
-18
lines changed

app/code/Magento/Cron/Model/Schedule.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,16 @@ public function __construct(
7171
}
7272

7373
/**
74-
* @return void
74+
* @inheritdoc
7575
*/
7676
public function _construct()
7777
{
7878
$this->_init(\Magento\Cron\Model\ResourceModel\Schedule::class);
7979
}
8080

8181
/**
82+
* Set cron expression.
83+
*
8284
* @param string $expr
8385
* @return $this
8486
* @throws \Magento\Framework\Exception\CronException
@@ -95,7 +97,7 @@ public function setCronExpr($expr)
9597
}
9698

9799
/**
98-
* Checks the observer's cron expression against time
100+
* Checks the observer's cron expression against time.
99101
*
100102
* Supports $this->setCronExpr('* 0-5,10-59/5 2-10,15-25 january-june/2 mon-fri')
101103
*
@@ -125,6 +127,8 @@ public function trySchedule()
125127
}
126128

127129
/**
130+
* Match cron expression.
131+
*
128132
* @param string $expr
129133
* @param int $num
130134
* @return bool
@@ -191,6 +195,8 @@ public function matchCronExpression($expr, $num)
191195
}
192196

193197
/**
198+
* Get number of a month.
199+
*
194200
* @param int|string $value
195201
* @return bool|int|string
196202
*/

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

Lines changed: 35 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
use Magento\Framework\Profiler\Driver\Standard\StatFactory;
1818

1919
/**
20+
* The observer for processing cron jobs.
21+
*
2022
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2123
*/
2224
class ProcessCronQueueObserver implements ObserverInterface
@@ -154,8 +156,9 @@ class ProcessCronQueueObserver implements ObserverInterface
154156
* @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
155157
* @param \Magento\Framework\Process\PhpExecutableFinderFactory $phpExecutableFinderFactory
156158
* @param \Psr\Log\LoggerInterface $logger
157-
* @param \Magento\Framework\App\State $state
159+
* @param State $state
158160
* @param StatFactory $statFactory
161+
* @param \Magento\Framework\Lock\LockManagerInterface $lockManager
159162
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
160163
*/
161164
public function __construct(
@@ -378,8 +381,9 @@ private function getProfilingStat()
378381
}
379382

380383
/**
381-
* Return job collection from data base with status 'pending'
384+
* Return job collection from data base with status 'pending'.
382385
*
386+
* @param string $groupId
383387
* @return \Magento\Cron\Model\ResourceModel\Schedule\Collection
384388
*/
385389
private function getPendingSchedules($groupId)
@@ -464,8 +468,8 @@ protected function _generateJobs($jobs, $exists, $groupId)
464468
/**
465469
* Clean expired jobs
466470
*
467-
* @param $groupId
468-
* @param $currentTime
471+
* @param string $groupId
472+
* @param int $currentTime
469473
* @return void
470474
*/
471475
private function cleanupJobs($groupId, $currentTime)
@@ -516,6 +520,8 @@ private function cleanupJobs($groupId, $currentTime)
516520
}
517521

518522
/**
523+
* Get config of schedule.
524+
*
519525
* @param array $jobConfig
520526
* @return mixed
521527
*/
@@ -530,6 +536,8 @@ protected function getConfigSchedule($jobConfig)
530536
}
531537

532538
/**
539+
* Save a schedule of cron job.
540+
*
533541
* @param string $jobCode
534542
* @param string $cronExpression
535543
* @param int $timeInterval
@@ -562,6 +570,8 @@ protected function saveSchedule($jobCode, $cronExpression, $timeInterval, $exist
562570
}
563571

564572
/**
573+
* Create a schedule of cron job.
574+
*
565575
* @param string $jobCode
566576
* @param string $cronExpression
567577
* @param int $time
@@ -580,6 +590,8 @@ protected function createSchedule($jobCode, $cronExpression, $time)
580590
}
581591

582592
/**
593+
* Get time interval for scheduling.
594+
*
583595
* @param string $groupId
584596
* @return int
585597
*/
@@ -592,8 +604,9 @@ protected function getScheduleTimeInterval($groupId)
592604
}
593605

594606
/**
595-
* Clean up scheduled jobs that are disabled in the configuration
596-
* This can happen when you turn off a cron job in the config and flush the cache
607+
* Clean up scheduled jobs that are disabled in the configuration.
608+
*
609+
* This can happen when you turn off a cron job in the config and flush the cache.
597610
*
598611
* @param string $groupId
599612
* @return void
@@ -624,6 +637,8 @@ private function cleanupDisabledJobs($groupId)
624637
}
625638

626639
/**
640+
* Get cron expression of cron job.
641+
*
627642
* @param array $jobConfig
628643
* @return null|string
629644
*/
@@ -643,8 +658,9 @@ private function getCronExpression($jobConfig)
643658
}
644659

645660
/**
646-
* Clean up scheduled jobs that do not match their cron expression anymore
647-
* This can happen when you change the cron expression and flush the cache
661+
* Clean up scheduled jobs that do not match their cron expression anymore.
662+
*
663+
* This can happen when you change the cron expression and flush the cache.
648664
*
649665
* @return $this
650666
*/
@@ -663,9 +679,10 @@ private function cleanupScheduleMismatches()
663679
}
664680

665681
/**
666-
* Get CronGroup Configuration Value
682+
* Get CronGroup Configuration Value.
667683
*
668-
* @param $groupId
684+
* @param string $groupId
685+
* @param string $path
669686
* @return int
670687
*/
671688
private function getCronGroupConfigurationValue($groupId, $path)
@@ -677,9 +694,9 @@ private function getCronGroupConfigurationValue($groupId, $path)
677694
}
678695

679696
/**
680-
* Is Group In Filter
697+
* Is Group In Filter.
681698
*
682-
* @param $groupId
699+
* @param string $groupId
683700
* @return bool
684701
*/
685702
private function isGroupInFilter($groupId): bool
@@ -689,11 +706,11 @@ private function isGroupInFilter($groupId): bool
689706
}
690707

691708
/**
692-
* Process pending jobs
709+
* Process pending jobs.
693710
*
694-
* @param $groupId
695-
* @param $jobsRoot
696-
* @param $currentTime
711+
* @param string $groupId
712+
* @param array $jobsRoot
713+
* @param int $currentTime
697714
*/
698715
private function processPendingJobs($groupId, $jobsRoot, $currentTime)
699716
{
@@ -730,6 +747,8 @@ private function processPendingJobs($groupId, $jobsRoot, $currentTime)
730747
}
731748

732749
/**
750+
* Process error messages.
751+
*
733752
* @param Schedule $schedule
734753
* @param \Exception $exception
735754
* @return void

0 commit comments

Comments
 (0)