diff --git a/core/Command/Background/JobWorker.php b/core/Command/Background/JobWorker.php index f7c85cc0bae2f..747e8ce79fca1 100644 --- a/core/Command/Background/JobWorker.php +++ b/core/Command/Background/JobWorker.php @@ -1,6 +1,7 @@ writeln('Running job ' . get_class($job) . ' with ID ' . $job->getId()); + $jobClassName = get_class($job); + $output->writeln('Running job ' . $jobClassName . ' with ID ' . $job->getId()); if ($output->isVerbose()) { $this->printJobInfo($job->getId(), $job, $output); } + memory_reset_peak_usage(); + $jobClassId = $this->jobClassesRegistry->getId($jobClassName); + $jobRunId = $this->jobRuns->started($jobClassId); + $startTime = microtime(true); $job->start($this->jobList); + $timeSpent = microtime(true) - $startTime; + $jobMemoryPeak = memory_get_peak_usage(); + // TODO Job failure will never be catched here because exceptions are catched within $job->start method + // The error will only be visible in server logs. + // It should be a temporary state until a proper job runner is implemented. + $this->jobRuns->finished($jobRunId, (int)($timeSpent * 1000), (int)($jobMemoryPeak / 1024)); + $output->writeln('Job ' . $job->getId() . ' has finished', OutputInterface::VERBOSITY_VERBOSE); // clean up after unclean jobs