Skip to content

Commit c2c8a75

Browse files
author
Dmytro Voskoboinikov
committed
Merge branch 'MAGETWO-83782' into 2.2-bugfixes-280218
2 parents 81b24e6 + 4e0bb58 commit c2c8a75

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,15 @@ protected function _runJob($scheduledTime, $currentTime, $jobConfig, $schedule,
290290

291291
try {
292292
call_user_func_array($callback, [$schedule]);
293-
} catch (\Exception $e) {
293+
} 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/Model/CronJobException.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,27 @@
1212

1313
class CronJobException
1414
{
15+
/**
16+
* @var \Throwable|null
17+
*/
18+
private $exception;
19+
20+
/**
21+
* @param \Throwable|null $exception
22+
*/
23+
public function __construct(\Throwable $exception = null)
24+
{
25+
$this->exception = $exception;
26+
}
27+
28+
/**
29+
* @throws \Throwable
30+
*/
1531
public function execute()
1632
{
17-
throw new \Exception('Test exception');
33+
if (!$this->exception) {
34+
$this->exception = new \Exception('Test exception');
35+
}
36+
throw $this->exception;
1837
}
1938
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ public function testDispatchExceptionInCallback(
468468
*/
469469
public function dispatchExceptionInCallbackDataProvider()
470470
{
471+
$throwable = new \TypeError();
471472
return [
472473
'non-callable callback' => [
473474
'Not_Existed_Class',
@@ -483,6 +484,19 @@ public function dispatchExceptionInCallbackDataProvider()
483484
2,
484485
new \Exception(__('Test exception'))
485486
],
487+
'throwable in execution' => [
488+
'CronJobException',
489+
new \Magento\Cron\Test\Unit\Model\CronJobException(
490+
$throwable
491+
),
492+
'Error when running a cron job',
493+
2,
494+
new \RuntimeException(
495+
'Error when running a cron job',
496+
0,
497+
$throwable
498+
)
499+
],
486500
];
487501
}
488502

0 commit comments

Comments
 (0)