From ee24b58a2ca44caf29c73dbeef71180b8b78e587 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Thu, 20 May 2021 12:28:00 +0300 Subject: [PATCH] job fix --- application/Espo/Core/Console/Commands/RunJob.php | 8 +++++++- application/Espo/Core/Job/JobRunner.php | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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;