@@ -59,57 +59,57 @@ class ProcessCronQueueObserver implements ObserverInterface
59
59
/**
60
60
* @var \Magento\Cron\Model\ResourceModel\Schedule\Collection
61
61
*/
62
- private $ pendingSchedules ;
62
+ protected $ pendingSchedules ;
63
63
64
64
/**
65
65
* @var \Magento\Cron\Model\ConfigInterface
66
66
*/
67
- private $ config ;
67
+ protected $ _config ;
68
68
69
69
/**
70
70
* @var \Magento\Framework\App\ObjectManager
71
71
*/
72
- private $ objectManager ;
72
+ protected $ _objectManager ;
73
73
74
74
/**
75
75
* @var \Magento\Framework\App\CacheInterface
76
76
*/
77
- private $ cache ;
77
+ protected $ _cache ;
78
78
79
79
/**
80
80
* @var \Magento\Framework\App\Config\ScopeConfigInterface
81
81
*/
82
- private $ scopeConfig ;
82
+ protected $ _scopeConfig ;
83
83
84
84
/**
85
85
* @var ScheduleFactory
86
86
*/
87
- private $ scheduleFactory ;
87
+ protected $ _scheduleFactory ;
88
88
89
89
/**
90
90
* @var \Magento\Framework\App\Console\Request
91
91
*/
92
- private $ request ;
92
+ protected $ _request ;
93
93
94
94
/**
95
95
* @var \Magento\Framework\ShellInterface
96
96
*/
97
- private $ shell ;
97
+ protected $ _shell ;
98
98
99
99
/**
100
100
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
101
101
*/
102
- private $ timezone ;
102
+ protected $ timezone ;
103
103
104
104
/**
105
105
* @var \Symfony\Component\Process\PhpExecutableFinder
106
106
*/
107
- private $ phpExecutableFinder ;
107
+ protected $ phpExecutableFinder ;
108
108
109
109
/**
110
110
* @var \Psr\Log\LoggerInterface
111
111
*/
112
- private $ logger ;
112
+ protected $ logger ;
113
113
114
114
/**
115
115
* @var \Magento\Framework\App\State
@@ -153,13 +153,13 @@ public function __construct(
153
153
\Psr \Log \LoggerInterface $ logger ,
154
154
\Magento \Framework \App \State $ state
155
155
) {
156
- $ this ->objectManager = $ objectManager ;
157
- $ this ->scheduleFactory = $ scheduleFactory ;
158
- $ this ->cache = $ cache ;
159
- $ this ->config = $ config ;
160
- $ this ->scopeConfig = $ scopeConfig ;
161
- $ this ->request = $ request ;
162
- $ this ->shell = $ shell ;
156
+ $ this ->_objectManager = $ objectManager ;
157
+ $ this ->_scheduleFactory = $ scheduleFactory ;
158
+ $ this ->_cache = $ cache ;
159
+ $ this ->_config = $ config ;
160
+ $ this ->_scopeConfig = $ scopeConfig ;
161
+ $ this ->_request = $ request ;
162
+ $ this ->_shell = $ shell ;
163
163
$ this ->timezone = $ timezone ;
164
164
$ this ->phpExecutableFinder = $ phpExecutableFinderFactory ->create ();
165
165
$ this ->logger = $ logger ;
@@ -179,29 +179,29 @@ public function __construct(
179
179
*/
180
180
public function execute (\Magento \Framework \Event \Observer $ observer )
181
181
{
182
- $ pendingJobs = $ this ->getPendingSchedules ();
182
+ $ pendingJobs = $ this ->_getPendingSchedules ();
183
183
$ currentTime = $ this ->timezone ->scopeTimeStamp ();
184
- $ jobGroupsRoot = $ this ->config ->getJobs ();
184
+ $ jobGroupsRoot = $ this ->_config ->getJobs ();
185
185
186
186
$ phpPath = $ this ->phpExecutableFinder ->find () ?: 'php ' ;
187
187
188
188
foreach ($ jobGroupsRoot as $ groupId => $ jobsRoot ) {
189
- $ this ->cleanup ($ groupId );
190
- $ this ->generate ($ groupId );
191
- if ($ this ->request ->getParam ('group ' ) !== null
192
- && $ this ->request ->getParam ('group ' ) !== '\'' . ($ groupId ) . '\''
193
- && $ this ->request ->getParam ('group ' ) !== $ groupId
189
+ $ this ->_cleanup ($ groupId );
190
+ $ this ->_generate ($ groupId );
191
+ if ($ this ->_request ->getParam ('group ' ) !== null
192
+ && $ this ->_request ->getParam ('group ' ) !== '\'' . ($ groupId ) . '\''
193
+ && $ this ->_request ->getParam ('group ' ) !== $ groupId
194
194
) {
195
195
continue ;
196
196
}
197
- if (($ this ->request ->getParam (self ::STANDALONE_PROCESS_STARTED ) !== '1 ' ) && (
198
- $ this ->scopeConfig ->getValue (
197
+ if (($ this ->_request ->getParam (self ::STANDALONE_PROCESS_STARTED ) !== '1 ' ) && (
198
+ $ this ->_scopeConfig ->getValue (
199
199
'system/cron/ ' . $ groupId . '/use_separate_process ' ,
200
200
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
201
201
) == 1
202
202
)
203
203
) {
204
- $ this ->shell ->execute (
204
+ $ this ->_shell ->execute (
205
205
$ phpPath . ' %s cron:run --group= ' . $ groupId . ' -- ' . Cli::INPUT_KEY_BOOTSTRAP . '= '
206
206
. self ::STANDALONE_PROCESS_STARTED . '=1 ' ,
207
207
[
@@ -225,7 +225,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
225
225
226
226
try {
227
227
if ($ schedule ->tryLockJob ()) {
228
- $ this ->runJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId );
228
+ $ this ->_runJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId );
229
229
}
230
230
} catch (\Exception $ e ) {
231
231
$ schedule ->setMessages ($ e ->getMessage ());
@@ -261,9 +261,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
261
261
* @return void
262
262
* @throws \Exception
263
263
*/
264
- public function runJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId )
264
+ protected function _runJob ($ scheduledTime , $ currentTime , $ jobConfig , $ schedule , $ groupId )
265
265
{
266
- $ scheduleLifetime = (int )$ this ->scopeConfig ->getValue (
266
+ $ scheduleLifetime = (int )$ this ->_scopeConfig ->getValue (
267
267
'system/cron/ ' . $ groupId . '/ ' . self ::XML_PATH_SCHEDULE_LIFETIME ,
268
268
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
269
269
);
@@ -277,7 +277,7 @@ public function runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $gro
277
277
$ schedule ->setStatus (Schedule::STATUS_ERROR );
278
278
throw new \Exception ('No callbacks found ' );
279
279
}
280
- $ model = $ this ->objectManager ->create ($ jobConfig ['instance ' ]);
280
+ $ model = $ this ->_objectManager ->create ($ jobConfig ['instance ' ]);
281
281
$ callback = [$ model , $ jobConfig ['method ' ]];
282
282
if (!is_callable ($ callback )) {
283
283
$ schedule ->setStatus (Schedule::STATUS_ERROR );
@@ -306,10 +306,10 @@ public function runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $gro
306
306
*
307
307
* @return \Magento\Cron\Model\ResourceModel\Schedule\Collection
308
308
*/
309
- public function getPendingSchedules ()
309
+ protected function _getPendingSchedules ()
310
310
{
311
311
if (!$ this ->pendingSchedules ) {
312
- $ this ->pendingSchedules = $ this ->scheduleFactory ->create ()->getCollection ()->addFieldToFilter (
312
+ $ this ->pendingSchedules = $ this ->_scheduleFactory ->create ()->getCollection ()->addFieldToFilter (
313
313
'status ' ,
314
314
Schedule::STATUS_PENDING
315
315
)->load ();
@@ -323,13 +323,13 @@ public function getPendingSchedules()
323
323
* @param string $groupId
324
324
* @return $this
325
325
*/
326
- public function generate ($ groupId )
326
+ protected function _generate ($ groupId )
327
327
{
328
328
/**
329
329
* check if schedule generation is needed
330
330
*/
331
- $ lastRun = (int )$ this ->cache ->load (self ::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT . $ groupId );
332
- $ rawSchedulePeriod = (int )$ this ->scopeConfig ->getValue (
331
+ $ lastRun = (int )$ this ->_cache ->load (self ::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT . $ groupId );
332
+ $ rawSchedulePeriod = (int )$ this ->_scopeConfig ->getValue (
333
333
'system/cron/ ' . $ groupId . '/ ' . self ::XML_PATH_SCHEDULE_GENERATE_EVERY ,
334
334
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
335
335
);
@@ -338,7 +338,7 @@ public function generate($groupId)
338
338
return $ this ;
339
339
}
340
340
341
- $ schedules = $ this ->getPendingSchedules ();
341
+ $ schedules = $ this ->_getPendingSchedules ();
342
342
$ exists = [];
343
343
/** @var Schedule $schedule */
344
344
foreach ($ schedules as $ schedule ) {
@@ -350,13 +350,13 @@ public function generate($groupId)
350
350
*/
351
351
$ jobs = $ this ->getJobs ();
352
352
$ this ->invalid = [];
353
- $ this ->generateJobs ($ jobs [$ groupId ], $ exists , $ groupId );
353
+ $ this ->_generateJobs ($ jobs [$ groupId ], $ exists , $ groupId );
354
354
$ this ->cleanupScheduleMismatches ();
355
355
356
356
/**
357
357
* save time schedules generation was ran with no expiration
358
358
*/
359
- $ this ->cache ->save (
359
+ $ this ->_cache ->save (
360
360
$ this ->timezone ->scopeTimeStamp (),
361
361
self ::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT . $ groupId ,
362
362
['crontab ' ],
@@ -374,7 +374,7 @@ public function generate($groupId)
374
374
* @param string $groupId
375
375
* @return $this
376
376
*/
377
- private function generateJobs ($ jobs , $ exists , $ groupId )
377
+ protected function _generateJobs ($ jobs , $ exists , $ groupId )
378
378
{
379
379
foreach ($ jobs as $ jobCode => $ jobConfig ) {
380
380
$ cronExpression = $ this ->getCronExpression ($ jobConfig );
@@ -394,13 +394,13 @@ private function generateJobs($jobs, $exists, $groupId)
394
394
* @param string $groupId
395
395
* @return $this
396
396
*/
397
- private function cleanup ($ groupId )
397
+ protected function _cleanup ($ groupId )
398
398
{
399
399
$ this ->cleanupDisabledJobs ($ groupId );
400
400
401
401
// check if history cleanup is needed
402
- $ lastCleanup = (int )$ this ->cache ->load (self ::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $ groupId );
403
- $ historyCleanUp = (int )$ this ->scopeConfig ->getValue (
402
+ $ lastCleanup = (int )$ this ->_cache ->load (self ::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $ groupId );
403
+ $ historyCleanUp = (int )$ this ->_scopeConfig ->getValue (
404
404
'system/cron/ ' . $ groupId . '/ ' . self ::XML_PATH_HISTORY_CLEANUP_EVERY ,
405
405
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
406
406
);
@@ -409,7 +409,7 @@ private function cleanup($groupId)
409
409
}
410
410
411
411
// check how long the record should stay unprocessed before marked as MISSED
412
- $ scheduleLifetime = (int )$ this ->scopeConfig ->getValue (
412
+ $ scheduleLifetime = (int )$ this ->_scopeConfig ->getValue (
413
413
'system/cron/ ' . $ groupId . '/ ' . self ::XML_PATH_SCHEDULE_LIFETIME ,
414
414
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
415
415
);
@@ -418,16 +418,16 @@ private function cleanup($groupId)
418
418
/**
419
419
* @var \Magento\Cron\Model\ResourceModel\Schedule\Collection $history
420
420
*/
421
- $ history = $ this ->scheduleFactory ->create ()->getCollection ()->addFieldToFilter (
421
+ $ history = $ this ->_scheduleFactory ->create ()->getCollection ()->addFieldToFilter (
422
422
'status ' ,
423
423
['in ' => [Schedule::STATUS_SUCCESS , Schedule::STATUS_MISSED , Schedule::STATUS_ERROR ]]
424
424
)->load ();
425
425
426
- $ historySuccess = (int )$ this ->scopeConfig ->getValue (
426
+ $ historySuccess = (int )$ this ->_scopeConfig ->getValue (
427
427
'system/cron/ ' . $ groupId . '/ ' . self ::XML_PATH_HISTORY_SUCCESS ,
428
428
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
429
429
);
430
- $ historyFailure = (int )$ this ->scopeConfig ->getValue (
430
+ $ historyFailure = (int )$ this ->_scopeConfig ->getValue (
431
431
'system/cron/ ' . $ groupId . '/ ' . self ::XML_PATH_HISTORY_FAILURE ,
432
432
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
433
433
);
@@ -448,7 +448,7 @@ private function cleanup($groupId)
448
448
}
449
449
450
450
// save time history cleanup was ran with no expiration
451
- $ this ->cache ->save (
451
+ $ this ->_cache ->save (
452
452
$ this ->timezone ->scopeTimeStamp (),
453
453
self ::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $ groupId ,
454
454
['crontab ' ],
@@ -462,9 +462,9 @@ private function cleanup($groupId)
462
462
* @param array $jobConfig
463
463
* @return mixed
464
464
*/
465
- private function getConfigSchedule ($ jobConfig )
465
+ protected function getConfigSchedule ($ jobConfig )
466
466
{
467
- $ cronExpr = $ this ->scopeConfig ->getValue (
467
+ $ cronExpr = $ this ->_scopeConfig ->getValue (
468
468
$ jobConfig ['config_path ' ],
469
469
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
470
470
);
@@ -479,7 +479,7 @@ private function getConfigSchedule($jobConfig)
479
479
* @param array $exists
480
480
* @return void
481
481
*/
482
- private function saveSchedule ($ jobCode , $ cronExpression , $ timeInterval , $ exists )
482
+ protected function saveSchedule ($ jobCode , $ cronExpression , $ timeInterval , $ exists )
483
483
{
484
484
$ currentTime = $ this ->timezone ->scopeTimeStamp ();
485
485
$ timeAhead = $ currentTime + $ timeInterval ;
@@ -510,9 +510,9 @@ private function saveSchedule($jobCode, $cronExpression, $timeInterval, $exists)
510
510
* @param int $time
511
511
* @return Schedule
512
512
*/
513
- private function generateSchedule ($ jobCode , $ cronExpression , $ time )
513
+ protected function generateSchedule ($ jobCode , $ cronExpression , $ time )
514
514
{
515
- $ schedule = $ this ->scheduleFactory ->create ()
515
+ $ schedule = $ this ->_scheduleFactory ->create ()
516
516
->setCronExpr ($ cronExpression )
517
517
->setJobCode ($ jobCode )
518
518
->setStatus (Schedule::STATUS_PENDING )
@@ -526,9 +526,9 @@ private function generateSchedule($jobCode, $cronExpression, $time)
526
526
* @param string $groupId
527
527
* @return int
528
528
*/
529
- private function getScheduleTimeInterval ($ groupId )
529
+ protected function getScheduleTimeInterval ($ groupId )
530
530
{
531
- $ scheduleAheadFor = (int )$ this ->scopeConfig ->getValue (
531
+ $ scheduleAheadFor = (int )$ this ->_scopeConfig ->getValue (
532
532
'system/cron/ ' . $ groupId . '/ ' . self ::XML_PATH_SCHEDULE_AHEAD_FOR ,
533
533
\Magento \Store \Model \ScopeInterface::SCOPE_STORE
534
534
);
@@ -550,7 +550,7 @@ public function cleanupDisabledJobs($groupId)
550
550
foreach ($ jobs [$ groupId ] as $ jobCode => $ jobConfig ) {
551
551
if (!$ this ->getCronExpression ($ jobConfig )) {
552
552
/** @var \Magento\Cron\Model\ResourceModel\Schedule $scheduleResource */
553
- $ scheduleResource = $ this ->scheduleFactory ->create ()->getResource ();
553
+ $ scheduleResource = $ this ->_scheduleFactory ->create ()->getResource ();
554
554
$ scheduleResource ->getConnection ()->delete ($ scheduleResource ->getMainTable (), [
555
555
'status=? ' => Schedule::STATUS_PENDING ,
556
556
'job_code=? ' => $ jobCode ,
@@ -584,11 +584,11 @@ private function getCronExpression($jobConfig)
584
584
*
585
585
* @return $this
586
586
*/
587
- public function cleanupScheduleMismatches ()
587
+ private function cleanupScheduleMismatches ()
588
588
{
589
589
foreach ($ this ->invalid as $ jobCode => $ scheduledAtList ) {
590
590
/** @var \Magento\Cron\Model\ResourceModel\Schedule $scheduleResource */
591
- $ scheduleResource = $ this ->scheduleFactory ->create ()->getResource ();
591
+ $ scheduleResource = $ this ->_scheduleFactory ->create ()->getResource ();
592
592
$ scheduleResource ->getConnection ()->delete ($ scheduleResource ->getMainTable (), [
593
593
'status=? ' => Schedule::STATUS_PENDING ,
594
594
'job_code=? ' => $ jobCode ,
@@ -604,7 +604,7 @@ public function cleanupScheduleMismatches()
604
604
private function getJobs ()
605
605
{
606
606
if ($ this ->jobs === null ) {
607
- $ this ->jobs = $ this ->config ->getJobs ();
607
+ $ this ->jobs = $ this ->_config ->getJobs ();
608
608
}
609
609
return $ this ->jobs ;
610
610
}
0 commit comments