9
9
*/
10
10
namespace Magento \Cron \Observer ;
11
11
12
+ use Magento \Cron \Model \ResourceModel \Schedule \Collection as ScheduleCollection ;
12
13
use Magento \Cron \Model \Schedule ;
13
14
use Magento \Framework \App \State ;
14
15
use Magento \Framework \Console \Cli ;
@@ -83,7 +84,7 @@ class ProcessCronQueueObserver implements ObserverInterface
83
84
const MAX_RETRIES = 5 ;
84
85
85
86
/**
86
- * @var \Magento\Cron\Model\ResourceModel\Schedule\Collection
87
+ * @var ScheduleCollection
87
88
*/
88
89
protected $ _pendingSchedules ;
89
90
@@ -278,12 +279,12 @@ function ($groupId) use ($currentTime) {
278
279
*
279
280
* It should be taken by standalone (child) process, not by the parent process.
280
281
*
281
- * @param int $groupId
282
+ * @param string $groupId
282
283
* @param callable $callback
283
284
*
284
285
* @return void
285
286
*/
286
- private function lockGroup ($ groupId , callable $ callback )
287
+ private function lockGroup (string $ groupId , callable $ callback ): void
287
288
{
288
289
if (!$ this ->lockManager ->lock (self ::LOCK_PREFIX . $ groupId , self ::LOCK_TIMEOUT )) {
289
290
$ this ->logger ->warning (
@@ -399,7 +400,7 @@ function () use ($schedule) {
399
400
* @param string $jobName
400
401
* @return void
401
402
*/
402
- private function startProfiling (string $ jobName = '' )
403
+ private function startProfiling (string $ jobName = '' ): void
403
404
{
404
405
$ this ->statProfiler ->clear ();
405
406
$ this ->statProfiler ->start (
@@ -416,7 +417,7 @@ private function startProfiling(string $jobName = '')
416
417
* @param string $jobName
417
418
* @return void
418
419
*/
419
- private function stopProfiling (string $ jobName = '' )
420
+ private function stopProfiling (string $ jobName = '' ): void
420
421
{
421
422
$ this ->statProfiler ->stop (
422
423
sprintf (self ::CRON_TIMERID , $ jobName ),
@@ -445,9 +446,9 @@ private function getProfilingStat(string $jobName): string
445
446
* Return job collection from data base with status 'pending'.
446
447
*
447
448
* @param string $groupId
448
- * @return \Magento\Cron\Model\ResourceModel\Schedule\Collection
449
+ * @return ScheduleCollection
449
450
*/
450
- private function getPendingSchedules ($ groupId )
451
+ private function getPendingSchedules (string $ groupId ): ScheduleCollection
451
452
{
452
453
$ jobs = $ this ->_config ->getJobs ();
453
454
$ pendingJobs = $ this ->_scheduleFactory ->create ()->getCollection ();
@@ -462,7 +463,7 @@ private function getPendingSchedules($groupId)
462
463
* @param string $groupId
463
464
* @return $this
464
465
*/
465
- private function generateSchedules ($ groupId )
466
+ private function generateSchedules (string $ groupId ): self
466
467
{
467
468
/**
468
469
* check if schedule generation is needed
@@ -533,13 +534,13 @@ protected function _generateJobs($jobs, $exists, $groupId)
533
534
* @param int $currentTime
534
535
* @return void
535
536
*/
536
- private function cleanupJobs ($ groupId , $ currentTime )
537
+ private function cleanupJobs (string $ groupId , int $ currentTime ): void
537
538
{
538
539
// check if history cleanup is needed
539
540
$ lastCleanup = (int )$ this ->_cache ->load (self ::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $ groupId );
540
541
$ historyCleanUp = (int )$ this ->getCronGroupConfigurationValue ($ groupId , self ::XML_PATH_HISTORY_CLEANUP_EVERY );
541
542
if ($ lastCleanup > $ this ->dateTime ->gmtTimestamp () - $ historyCleanUp * self ::SECONDS_IN_MINUTE ) {
542
- return $ this ;
543
+ return ;
543
544
}
544
545
// save time history cleanup was ran with no expiration
545
546
$ this ->_cache ->save (
@@ -674,7 +675,7 @@ protected function getScheduleTimeInterval($groupId)
674
675
* @param string $groupId
675
676
* @return void
676
677
*/
677
- private function cleanupDisabledJobs ($ groupId )
678
+ private function cleanupDisabledJobs (string $ groupId ): void
678
679
{
679
680
$ jobs = $ this ->_config ->getJobs ();
680
681
$ jobsToCleanup = [];
@@ -703,7 +704,7 @@ private function cleanupDisabledJobs($groupId)
703
704
* @param string $groupId
704
705
* @return void
705
706
*/
706
- private function cleanupRunningJobs ($ groupId )
707
+ private function cleanupRunningJobs (string $ groupId ): void
707
708
{
708
709
$ scheduleResource = $ this ->_scheduleFactory ->create ()->getResource ();
709
710
$ connection = $ scheduleResource ->getConnection ();
@@ -716,13 +717,11 @@ private function cleanupRunningJobs($groupId)
716
717
'status ' => \Magento \Cron \Model \Schedule::STATUS_ERROR ,
717
718
'messages ' => 'Time out '
718
719
],
719
- $ connection ->quoteInto (
720
- 'status = ? ' .
721
- 'AND job_code IN (?) ' .
722
- 'AND (scheduled_at < UTC_TIMESTAMP() - INTERVAL 1 DAY) ' ,
723
- \Magento \Cron \Model \Schedule::STATUS_RUNNING ,
724
- array_keys ($ jobs [$ groupId ])
725
- )
720
+ [
721
+ $ connection ->quoteInto ('status = ? ' , \Magento \Cron \Model \Schedule::STATUS_RUNNING ),
722
+ $ connection ->quoteInto ('job_code IN (?) ' , array_keys ($ jobs [$ groupId ])),
723
+ 'scheduled_at < UTC_TIMESTAMP() - INTERVAL 1 DAY '
724
+ ]
726
725
);
727
726
}
728
727
@@ -803,13 +802,13 @@ private function isGroupInFilter($groupId): bool
803
802
* @param array $jobsRoot
804
803
* @param int $currentTime
805
804
*/
806
- private function processPendingJobs ($ groupId , $ jobsRoot , $ currentTime )
805
+ private function processPendingJobs (string $ groupId , array $ jobsRoot , int $ currentTime ): void
807
806
{
808
- $ procesedJobs = [];
807
+ $ processedJobs = [];
809
808
$ pendingJobs = $ this ->getPendingSchedules ($ groupId );
810
809
/** @var Schedule $schedule */
811
810
foreach ($ pendingJobs as $ schedule ) {
812
- if (isset ($ procesedJobs [$ schedule ->getJobCode ()])) {
811
+ if (isset ($ processedJobs [$ schedule ->getJobCode ()])) {
813
812
// process only on job per run
814
813
continue ;
815
814
}
@@ -826,7 +825,7 @@ private function processPendingJobs($groupId, $jobsRoot, $currentTime)
826
825
$ this ->tryRunJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId );
827
826
828
827
if ($ schedule ->getStatus () === Schedule::STATUS_SUCCESS ) {
829
- $ procesedJobs [$ schedule ->getJobCode ()] = true ;
828
+ $ processedJobs [$ schedule ->getJobCode ()] = true ;
830
829
}
831
830
832
831
$ this ->retrier ->execute (
@@ -851,7 +850,7 @@ private function tryRunJob($scheduledTime, $currentTime, $jobConfig, $schedule,
851
850
{
852
851
// use sha1 to limit length
853
852
// phpcs:ignore Magento2.Security.InsecureFunction
854
- $ lockName = self ::LOCK_PREFIX . md5 ($ groupId . '_ ' . $ schedule ->getJobCode ());
853
+ $ lockName = self ::LOCK_PREFIX . md5 ($ groupId . '_ ' . $ schedule ->getJobCode ());
855
854
856
855
try {
857
856
for ($ retries = self ::MAX_RETRIES ; $ retries > 0 ; $ retries --) {
0 commit comments