@@ -138,11 +138,6 @@ class ProcessCronQueueObserver implements ObserverInterface
138
138
*/
139
139
private $ invalid = [];
140
140
141
- /**
142
- * @var array
143
- */
144
- private $ jobs ;
145
-
146
141
/**
147
142
* @var Stat
148
143
*/
@@ -389,7 +384,7 @@ private function getProfilingStat()
389
384
*/
390
385
private function getPendingSchedules ($ groupId )
391
386
{
392
- $ jobs = $ this ->getJobs ();
387
+ $ jobs = $ this ->_config -> getJobs ();
393
388
$ pendingJobs = $ this ->_scheduleFactory ->create ()->getCollection ();
394
389
$ pendingJobs ->addFieldToFilter ('status ' , Schedule::STATUS_PENDING );
395
390
$ pendingJobs ->addFieldToFilter ('job_code ' , ['in ' => array_keys ($ jobs [$ groupId ])]);
@@ -437,7 +432,7 @@ private function generateSchedules($groupId)
437
432
/**
438
433
* generate global crontab jobs
439
434
*/
440
- $ jobs = $ this ->getJobs ();
435
+ $ jobs = $ this ->_config -> getJobs ();
441
436
$ this ->invalid = [];
442
437
$ this ->_generateJobs ($ jobs [$ groupId ], $ exists , $ groupId );
443
438
$ this ->cleanupScheduleMismatches ();
@@ -500,11 +495,11 @@ private function cleanupJobs($groupId, $currentTime)
500
495
Schedule::STATUS_PENDING => max ($ historyFailure , $ historySuccess ) * self ::SECONDS_IN_MINUTE ,
501
496
];
502
497
503
- $ jobs = $ this ->getJobs ()[$ groupId ];
498
+ $ jobs = $ this ->_config -> getJobs ()[$ groupId ];
504
499
$ scheduleResource = $ this ->_scheduleFactory ->create ()->getResource ();
505
500
$ connection = $ scheduleResource ->getConnection ();
506
501
$ count = 0 ;
507
- foreach ($ historyLifetimes as $ status => $ time ) {
502
+ foreach ($ historyLifetimes as $ time ) {
508
503
$ count += $ connection ->delete (
509
504
$ scheduleResource ->getMainTable (),
510
505
[
@@ -605,7 +600,7 @@ protected function getScheduleTimeInterval($groupId)
605
600
*/
606
601
private function cleanupDisabledJobs ($ groupId )
607
602
{
608
- $ jobs = $ this ->getJobs ();
603
+ $ jobs = $ this ->_config -> getJobs ();
609
604
$ jobsToCleanup = [];
610
605
foreach ($ jobs [$ groupId ] as $ jobCode => $ jobConfig ) {
611
606
if (!$ this ->getCronExpression ($ jobConfig )) {
@@ -667,17 +662,6 @@ private function cleanupScheduleMismatches()
667
662
return $ this ;
668
663
}
669
664
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
-
681
665
/**
682
666
* Get CronGroup Configuration Value
683
667
*
@@ -690,7 +674,6 @@ private function getCronGroupConfigurationValue($groupId, $path)
690
674
'system/cron/ ' . $ groupId . '/ ' . $ path ,
691
675
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
692
676
);
693
- return $ scheduleLifetime ;
694
677
}
695
678
696
679
/**
@@ -737,20 +720,30 @@ private function processPendingJobs($groupId, $jobsRoot, $currentTime)
737
720
$ this ->_runJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId );
738
721
}
739
722
} 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 );
749
724
}
750
725
if ($ schedule ->getStatus () === Schedule::STATUS_SUCCESS ) {
751
726
$ procesedJobs [$ schedule ->getJobCode ()] = true ;
752
727
}
753
728
$ schedule ->save ();
754
729
}
755
730
}
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
+ }
756
749
}
0 commit comments