Skip to content

Commit 5053fa0

Browse files
author
Anton Evers
committed
Make cron observer methods public.
As I heard from @ishakhsuvarov Magento does not encourage usage of `protected` methods, because they do not encourage inheritance-based API. So composition in favor of inheritance. It's easier to maintain and reuse. I myself have already encountered scenarios where I wanted to use methods in this observer elsewhere in custom code, but I had to write duplicate code because these methods were `protected`.
1 parent 8ffa191 commit 5053fa0

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
248248
* @return void
249249
* @throws \Exception
250250
*/
251-
protected function runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId)
251+
public function runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId)
252252
{
253253
$scheduleLifetime = (int)$this->scopeConfig->getValue(
254254
'system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_LIFETIME,
@@ -293,7 +293,7 @@ protected function runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $
293293
*
294294
* @return \Magento\Cron\Model\ResourceModel\Schedule\Collection
295295
*/
296-
protected function getPendingSchedules()
296+
public function getPendingSchedules()
297297
{
298298
if (!$this->pendingSchedules) {
299299
$this->pendingSchedules = $this->scheduleFactory->create()->getCollection()->addFieldToFilter(
@@ -310,7 +310,7 @@ protected function getPendingSchedules()
310310
* @param string $groupId
311311
* @return $this
312312
*/
313-
protected function generate($groupId)
313+
public function generate($groupId)
314314
{
315315
/**
316316
* check if schedule generation is needed
@@ -359,7 +359,7 @@ protected function generate($groupId)
359359
* @param string $groupId
360360
* @return $this
361361
*/
362-
protected function generateJobs($jobs, $exists, $groupId)
362+
public function generateJobs($jobs, $exists, $groupId)
363363
{
364364
foreach ($jobs as $jobCode => $jobConfig) {
365365
$cronExpression = null;
@@ -389,7 +389,7 @@ protected function generateJobs($jobs, $exists, $groupId)
389389
* @param string $groupId
390390
* @return $this
391391
*/
392-
protected function cleanup($groupId)
392+
public function cleanup($groupId)
393393
{
394394
// check if history cleanup is needed
395395
$lastCleanup = (int)$this->cache->load(self::CACHE_KEY_LAST_HISTORY_CLEANUP_AT . $groupId);
@@ -455,7 +455,7 @@ protected function cleanup($groupId)
455455
* @param array $jobConfig
456456
* @return mixed
457457
*/
458-
protected function getConfigSchedule($jobConfig)
458+
public function getConfigSchedule($jobConfig)
459459
{
460460
$cronExpr = $this->scopeConfig->getValue(
461461
$jobConfig['config_path'],
@@ -472,7 +472,7 @@ protected function getConfigSchedule($jobConfig)
472472
* @param array $exists
473473
* @return void
474474
*/
475-
protected function saveSchedule($jobCode, $cronExpression, $timeInterval, $exists)
475+
public function saveSchedule($jobCode, $cronExpression, $timeInterval, $exists)
476476
{
477477
$currentTime = $this->timezone->scopeTimeStamp();
478478
$timeAhead = $currentTime + $timeInterval;
@@ -496,7 +496,7 @@ protected function saveSchedule($jobCode, $cronExpression, $timeInterval, $exist
496496
* @param int $time
497497
* @return Schedule
498498
*/
499-
protected function generateSchedule($jobCode, $cronExpression, $time)
499+
public function generateSchedule($jobCode, $cronExpression, $time)
500500
{
501501
$schedule = $this->scheduleFactory->create()
502502
->setCronExpr($cronExpression)
@@ -512,7 +512,7 @@ protected function generateSchedule($jobCode, $cronExpression, $time)
512512
* @param string $groupId
513513
* @return int
514514
*/
515-
protected function getScheduleTimeInterval($groupId)
515+
public function getScheduleTimeInterval($groupId)
516516
{
517517
$scheduleAheadFor = (int)$this->scopeConfig->getValue(
518518
'system/cron/' . $groupId . '/' . self::XML_PATH_SCHEDULE_AHEAD_FOR,

0 commit comments

Comments
 (0)