Skip to content

Commit

Permalink
Record error messages on schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
fredden committed May 23, 2020
1 parent 374784a commit b9b3044
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Helper/Processor.php
Expand Up @@ -100,21 +100,25 @@ public function runScheduledJob($jobConfig, $schedule)
$jobCode = $schedule->getJobCode();

if (!isset($jobConfig['instance'], $jobConfig['method'])) {
$e = new LocalizedException(__('No callbacks found'));
$schedule->setStatus(Schedule::STATUS_ERROR);
$schedule->setMessages($e->getMessage());
$schedule->getResource()->save($schedule);
throw new \Exception('No callbacks found');
throw $e;
}

// dynamically create cron instances
$model = $this->cronInstanceFactory->create($jobConfig['instance']);
$callback = [$model, $jobConfig['method']];
if (!is_callable($callback)) {
$e = new LocalizedException(__(
'Invalid callback: %instance::%method can\'t be called',
$jobConfig
));
$schedule->setStatus(Schedule::STATUS_ERROR);
$schedule->setMessages($e->getMessage());
$schedule->getResource()->save($schedule);
throw new \Exception(sprintf('Invalid callback: %s::%s can\'t be called',
$jobConfig['instance'],
$jobConfig['method']
));
throw $e;
}

// Ensure we are the only process trying to run this job
Expand All @@ -133,6 +137,7 @@ public function runScheduledJob($jobConfig, $schedule)
call_user_func_array($callback, [$schedule]);
} catch (\Throwable $e) {
$schedule->setStatus(Schedule::STATUS_ERROR);
$schedule->setMessages($e->getMessage());
$schedule->getResource()->save($schedule);
$this->logger->error(sprintf(
'Cron Job %s has an error: %s.',
Expand Down

0 comments on commit b9b3044

Please sign in to comment.