Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions core/Command/Background/JobWorker.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

namespace OC\Core\Command\Background;

use OC\BackgroundJob\JobClassesRegistry;
use OC\BackgroundJob\JobRuns;
use OC\Core\Command\InterruptedException;
use OCP\BackgroundJob\IJobList;
use OCP\Files\ISetupManager;
Expand All @@ -19,15 +22,17 @@
use Symfony\Component\Console\Output\OutputInterface;

class JobWorker extends JobBase {

public function __construct(
protected IJobList $jobList,
protected LoggerInterface $logger,
private ITempManager $tempManager,
private ISetupManager $setupManager,
private readonly JobRuns $jobRuns,
private readonly JobClassesRegistry $jobClassesRegistry,
) {
parent::__construct($jobList, $logger);
}

#[\Override]
protected function configure(): void {
parent::configure();
Expand Down Expand Up @@ -124,13 +129,25 @@ protected function execute(InputInterface $input, OutputInterface $output): int
continue;
}

$output->writeln('Running job ' . get_class($job) . ' with ID ' . $job->getId());
$jobClassName = get_class($job);
Comment thread
Altahrim marked this conversation as resolved.
$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
Expand Down
Loading