Skip to content

Commit 1427a38

Browse files
author
Anton Evers
committed
rollback backword incompatible refactoring
1 parent d205a5e commit 1427a38

File tree

1 file changed

+60
-60
lines changed

1 file changed

+60
-60
lines changed

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

Lines changed: 60 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -59,57 +59,57 @@ class ProcessCronQueueObserver implements ObserverInterface
5959
/**
6060
* @var \Magento\Cron\Model\ResourceModel\Schedule\Collection
6161
*/
62-
private $pendingSchedules;
62+
protected $pendingSchedules;
6363

6464
/**
6565
* @var \Magento\Cron\Model\ConfigInterface
6666
*/
67-
private $config;
67+
protected $_config;
6868

6969
/**
7070
* @var \Magento\Framework\App\ObjectManager
7171
*/
72-
private $objectManager;
72+
protected $_objectManager;
7373

7474
/**
7575
* @var \Magento\Framework\App\CacheInterface
7676
*/
77-
private $cache;
77+
protected $_cache;
7878

7979
/**
8080
* @var \Magento\Framework\App\Config\ScopeConfigInterface
8181
*/
82-
private $scopeConfig;
82+
protected $_scopeConfig;
8383

8484
/**
8585
* @var ScheduleFactory
8686
*/
87-
private $scheduleFactory;
87+
protected $_scheduleFactory;
8888

8989
/**
9090
* @var \Magento\Framework\App\Console\Request
9191
*/
92-
private $request;
92+
protected $_request;
9393

9494
/**
9595
* @var \Magento\Framework\ShellInterface
9696
*/
97-
private $shell;
97+
protected $_shell;
9898

9999
/**
100100
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
101101
*/
102-
private $timezone;
102+
protected $timezone;
103103

104104
/**
105105
* @var \Symfony\Component\Process\PhpExecutableFinder
106106
*/
107-
private $phpExecutableFinder;
107+
protected $phpExecutableFinder;
108108

109109
/**
110110
* @var \Psr\Log\LoggerInterface
111111
*/
112-
private $logger;
112+
protected $logger;
113113

114114
/**
115115
* @var \Magento\Framework\App\State
@@ -153,13 +153,13 @@ public function __construct(
153153
\Psr\Log\LoggerInterface $logger,
154154
\Magento\Framework\App\State $state
155155
) {
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;
163163
$this->timezone = $timezone;
164164
$this->phpExecutableFinder = $phpExecutableFinderFactory->create();
165165
$this->logger = $logger;
@@ -179,29 +179,29 @@ public function __construct(
179179
*/
180180
public function execute(\Magento\Framework\Event\Observer $observer)
181181
{
182-
$pendingJobs = $this->getPendingSchedules();
182+
$pendingJobs = $this->_getPendingSchedules();
183183
$currentTime = $this->timezone->scopeTimeStamp();
184-
$jobGroupsRoot = $this->config->getJobs();
184+
$jobGroupsRoot = $this->_config->getJobs();
185185

186186
$phpPath = $this->phpExecutableFinder->find() ?: 'php';
187187

188188
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
194194
) {
195195
continue;
196196
}
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(
199199
'system/cron/' . $groupId . '/use_separate_process',
200200
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
201201
) == 1
202202
)
203203
) {
204-
$this->shell->execute(
204+
$this->_shell->execute(
205205
$phpPath . ' %s cron:run --group=' . $groupId . ' --' . Cli::INPUT_KEY_BOOTSTRAP . '='
206206
. self::STANDALONE_PROCESS_STARTED . '=1',
207207
[
@@ -225,7 +225,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
225225

226226
try {
227227
if ($schedule->tryLockJob()) {
228-
$this->runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId);
228+
$this->_runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId);
229229
}
230230
} catch (\Exception $e) {
231231
$schedule->setMessages($e->getMessage());
@@ -261,9 +261,9 @@ public function execute(\Magento\Framework\Event\Observer $observer)
261261
* @return void
262262
* @throws \Exception
263263
*/
264-
public function runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId)
264+
protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId)
265265
{
266-
$scheduleLifetime = (int)$this->scopeConfig->getValue(
266+
$scheduleLifetime = (int)$this->_scopeConfig->getValue(
267267
'system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME,
268268
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
269269
);
@@ -277,7 +277,7 @@ public function runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $gro
277277
$schedule->setStatus(Schedule::STATUS_ERROR);
278278
throw new \Exception('No callbacks found');
279279
}
280-
$model = $this->objectManager->create($jobConfig['instance']);
280+
$model = $this->_objectManager->create($jobConfig['instance']);
281281
$callback = [$model, $jobConfig['method']];
282282
if (!is_callable($callback)) {
283283
$schedule->setStatus(Schedule::STATUS_ERROR);
@@ -306,10 +306,10 @@ public function runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $gro
306306
*
307307
* @return \Magento\Cron\Model\ResourceModel\Schedule\Collection
308308
*/
309-
public function getPendingSchedules()
309+
protected function _getPendingSchedules()
310310
{
311311
if (!$this->pendingSchedules) {
312-
$this->pendingSchedules = $this->scheduleFactory->create()->getCollection()->addFieldToFilter(
312+
$this->pendingSchedules = $this->_scheduleFactory->create()->getCollection()->addFieldToFilter(
313313
'status',
314314
Schedule::STATUS_PENDING
315315
)->load();
@@ -323,13 +323,13 @@ public function getPendingSchedules()
323323
* @param string $groupId
324324
* @return $this
325325
*/
326-
public function generate($groupId)
326+
protected function _generate($groupId)
327327
{
328328
/**
329329
* check if schedule generation is needed
330330
*/
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(
333333
'system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_GENERATE_EVERY,
334334
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
335335
);
@@ -338,7 +338,7 @@ public function generate($groupId)
338338
return $this;
339339
}
340340

341-
$schedules = $this->getPendingSchedules();
341+
$schedules = $this->_getPendingSchedules();
342342
$exists = [];
343343
/** @var Schedule $schedule */
344344
foreach ($schedules as $schedule) {
@@ -350,13 +350,13 @@ public function generate($groupId)
350350
*/
351351
$jobs = $this->getJobs();
352352
$this->invalid = [];
353-
$this->generateJobs($jobs[$groupId], $exists, $groupId);
353+
$this->_generateJobs($jobs[$groupId], $exists, $groupId);
354354
$this->cleanupScheduleMismatches();
355355

356356
/**
357357
* save time schedules generation was ran with no expiration
358358
*/
359-
$this->cache->save(
359+
$this->_cache->save(
360360
$this->timezone->scopeTimeStamp(),
361361
self::CACHE_KEY_LAST_SCHEDULE_GENERATE_AT . $groupId,
362362
['crontab'],
@@ -374,7 +374,7 @@ public function generate($groupId)
374374
* @param string $groupId
375375
* @return $this
376376
*/
377-
private function generateJobs($jobs, $exists, $groupId)
377+
protected function _generateJobs($jobs, $exists, $groupId)
378378
{
379379
foreach ($jobs as $jobCode => $jobConfig) {
380380
$cronExpression = $this->getCronExpression($jobConfig);
@@ -394,13 +394,13 @@ private function generateJobs($jobs, $exists, $groupId)
394394
* @param string $groupId
395395
* @return $this
396396
*/
397-
private function cleanup($groupId)
397+
protected function _cleanup($groupId)
398398
{
399399
$this->cleanupDisabledJobs($groupId);
400400

401401
// 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(
404404
'system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_CLEANUP_EVERY,
405405
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
406406
);
@@ -409,7 +409,7 @@ private function cleanup($groupId)
409409
}
410410

411411
// check how long the record should stay unprocessed before marked as MISSED
412-
$scheduleLifetime = (int)$this->scopeConfig->getValue(
412+
$scheduleLifetime = (int)$this->_scopeConfig->getValue(
413413
'system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME,
414414
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
415415
);
@@ -418,16 +418,16 @@ private function cleanup($groupId)
418418
/**
419419
* @var \Magento\Cron\Model\ResourceModel\Schedule\Collection $history
420420
*/
421-
$history = $this->scheduleFactory->create()->getCollection()->addFieldToFilter(
421+
$history = $this->_scheduleFactory->create()->getCollection()->addFieldToFilter(
422422
'status',
423423
['in' => [Schedule::STATUS_SUCCESS, Schedule::STATUS_MISSED, Schedule::STATUS_ERROR]]
424424
)->load();
425425

426-
$historySuccess = (int)$this->scopeConfig->getValue(
426+
$historySuccess = (int)$this->_scopeConfig->getValue(
427427
'system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_SUCCESS,
428428
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
429429
);
430-
$historyFailure = (int)$this->scopeConfig->getValue(
430+
$historyFailure = (int)$this->_scopeConfig->getValue(
431431
'system/cron/' . $groupId . '/' . self::XML_PATH_HISTORY_FAILURE,
432432
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
433433
);
@@ -448,7 +448,7 @@ private function cleanup($groupId)
448448
}
449449

450450
// save time history cleanup was ran with no expiration
451-
$this->cache->save(
451+
$this->_cache->save(
452452
$this->timezone->scopeTimeStamp(),
453453
self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId,
454454
['crontab'],
@@ -462,9 +462,9 @@ private function cleanup($groupId)
462462
* @param array $jobConfig
463463
* @return mixed
464464
*/
465-
private function getConfigSchedule($jobConfig)
465+
protected function getConfigSchedule($jobConfig)
466466
{
467-
$cronExpr = $this->scopeConfig->getValue(
467+
$cronExpr = $this->_scopeConfig->getValue(
468468
$jobConfig['config_path'],
469469
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
470470
);
@@ -479,7 +479,7 @@ private function getConfigSchedule($jobConfig)
479479
* @param array $exists
480480
* @return void
481481
*/
482-
private function saveSchedule($jobCode, $cronExpression, $timeInterval, $exists)
482+
protected function saveSchedule($jobCode, $cronExpression, $timeInterval, $exists)
483483
{
484484
$currentTime = $this->timezone->scopeTimeStamp();
485485
$timeAhead = $currentTime + $timeInterval;
@@ -510,9 +510,9 @@ private function saveSchedule($jobCode, $cronExpression, $timeInterval, $exists)
510510
* @param int $time
511511
* @return Schedule
512512
*/
513-
private function generateSchedule($jobCode, $cronExpression, $time)
513+
protected function generateSchedule($jobCode, $cronExpression, $time)
514514
{
515-
$schedule = $this->scheduleFactory->create()
515+
$schedule = $this->_scheduleFactory->create()
516516
->setCronExpr($cronExpression)
517517
->setJobCode($jobCode)
518518
->setStatus(Schedule::STATUS_PENDING)
@@ -526,9 +526,9 @@ private function generateSchedule($jobCode, $cronExpression, $time)
526526
* @param string $groupId
527527
* @return int
528528
*/
529-
private function getScheduleTimeInterval($groupId)
529+
protected function getScheduleTimeInterval($groupId)
530530
{
531-
$scheduleAheadFor = (int)$this->scopeConfig->getValue(
531+
$scheduleAheadFor = (int)$this->_scopeConfig->getValue(
532532
'system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_AHEAD_FOR,
533533
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
534534
);
@@ -550,7 +550,7 @@ public function cleanupDisabledJobs($groupId)
550550
foreach ($jobs[$groupId] as $jobCode => $jobConfig) {
551551
if (!$this->getCronExpression($jobConfig)) {
552552
/** @var \Magento\Cron\Model\ResourceModel\Schedule $scheduleResource */
553-
$scheduleResource = $this->scheduleFactory->create()->getResource();
553+
$scheduleResource = $this->_scheduleFactory->create()->getResource();
554554
$scheduleResource->getConnection()->delete($scheduleResource->getMainTable(), [
555555
'status=?' => Schedule::STATUS_PENDING,
556556
'job_code=?' => $jobCode,
@@ -584,11 +584,11 @@ private function getCronExpression($jobConfig)
584584
*
585585
* @return $this
586586
*/
587-
public function cleanupScheduleMismatches()
587+
private function cleanupScheduleMismatches()
588588
{
589589
foreach ($this->invalid as $jobCode => $scheduledAtList) {
590590
/** @var \Magento\Cron\Model\ResourceModel\Schedule $scheduleResource */
591-
$scheduleResource = $this->scheduleFactory->create()->getResource();
591+
$scheduleResource = $this->_scheduleFactory->create()->getResource();
592592
$scheduleResource->getConnection()->delete($scheduleResource->getMainTable(), [
593593
'status=?' => Schedule::STATUS_PENDING,
594594
'job_code=?' => $jobCode,
@@ -604,7 +604,7 @@ public function cleanupScheduleMismatches()
604604
private function getJobs()
605605
{
606606
if ($this->jobs === null) {
607-
$this->jobs = $this->config->getJobs();
607+
$this->jobs = $this->_config->getJobs();
608608
}
609609
return $this->jobs;
610610
}

0 commit comments

Comments
 (0)