Skip to content

Commit a7ecf5f

Browse files
author
Oleksandr Gorkun
committed
MAGETWO-83782: [2.2] Cron_schedule forever increasing in size. Lots of pending jobs never cleared
1 parent 2e7bd9d commit a7ecf5f

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
227227
if ($schedule->tryLockJob()) {
228228
$this->_runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId);
229229
}
230-
} catch (\Throwable $e) {
230+
} catch (\Exception $e) {
231231
$schedule->setMessages($e->getMessage());
232232
if ($schedule->getStatus() === Schedule::STATUS_ERROR) {
233233
$this->logger->critical($e);
@@ -259,7 +259,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
259259
* @param Schedule $schedule
260260
* @param string $groupId
261261
* @return void
262-
* @throws \Throwable
262+
* @throws \Exception
263263
*/
264264
protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule, $groupId)
265265
{
@@ -292,6 +292,13 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
292292
call_user_func_array($callback, [$schedule]);
293293
} catch (\Throwable $e) {
294294
$schedule->setStatus(Schedule::STATUS_ERROR);
295+
if (!$e instanceof \Exception) {
296+
$e = new \RuntimeException(
297+
'Error when running a cron job',
298+
0,
299+
$e
300+
);
301+
}
295302
throw $e;
296303
}
297304

app/code/Magento/Cron/Test/Unit/Observer/ProcessCronQueueObserverTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,9 +489,13 @@ public function dispatchExceptionInCallbackDataProvider()
489489
new \Magento\Cron\Test\Unit\Model\CronJobException(
490490
$throwable
491491
),
492-
'',
492+
'Error when running a cron job',
493493
2,
494-
$throwable
494+
new \RuntimeException(
495+
'Error when running a cron job',
496+
0,
497+
$throwable
498+
)
495499
],
496500
];
497501
}

0 commit comments

Comments
 (0)