diff --git a/application/Espo/Core/Console/Commands/RunJob.php b/application/Espo/Core/Console/Commands/RunJob.php index 84fc19100b..a70ba944c8 100644 --- a/application/Espo/Core/Console/Commands/RunJob.php +++ b/application/Espo/Core/Console/Commands/RunJob.php @@ -87,7 +87,13 @@ class RunJob implements Command $this->jobManager->runJob($job); } catch (Throwable $e) { - $io->writeLine("Error: Job '{$jobName}' failed to execute."); + $message = "Error: Job '{$jobName}' failed to execute."; + + if ($e->getMessage()) { + $message .= ' ' . $e->getMessage(); + } + + $io->writeLine($message); return; } diff --git a/application/Espo/Core/Job/JobRunner.php b/application/Espo/Core/Job/JobRunner.php index 455625a62b..1cf32d63f1 100644 --- a/application/Espo/Core/Job/JobRunner.php +++ b/application/Espo/Core/Job/JobRunner.php @@ -165,7 +165,7 @@ class JobRunner $this->entityManager->saveEntity($job); if ($throwException && $exception) { - throw new $exception; + throw new $exception($exception->getMessage()); } if ($job->getScheduledJobId() && !$skipLog) { @@ -186,6 +186,13 @@ class JobRunner $obj = $this->jobFactory->create($jobName); if ($obj instanceof JobTargeted) { + if ( + $job->getTargetType() === null || + $job->getTargetId() === null + ) { + throw new Error("Can't run targeted job '{$jobName}' w/o target."); + } + $obj->run($job->getTargetType(), $job->getTargetId(), $job->getData()); return;