Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions core/Command/Background/Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@

namespace OC\Core\Command\Background;

use OCP\BackgroundJob\Events\BeforeJobExecutedEvent;
use OCP\BackgroundJob\Events\JobExecutedEvent;
use OCP\BackgroundJob\IJob;
use OCP\BackgroundJob\IJobList;
use OCP\EventDispatcher\IEventDispatcher;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -19,6 +22,7 @@
class Job extends Command {
public function __construct(
protected IJobList $jobList,
private IEventDispatcher $eventDispatcher,
) {
parent::__construct();
}
Expand Down Expand Up @@ -67,8 +71,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output->writeln('<error>Something went wrong when trying to retrieve Job with ID ' . $jobId . ' from database</error>');
return 1;
}
$this->eventDispatcher->dispatchTyped(new BeforeJobExecutedEvent($job));
/** @psalm-suppress DeprecatedMethod Calling execute until it is removed, then will switch to start */
$job->execute($this->jobList);
$this->eventDispatcher->dispatchTyped(new JobExecutedEvent($job));
$job = $this->jobList->getById($jobId);

if (($job === null) || ($lastRun !== $job->getLastRun())) {
Expand Down
6 changes: 6 additions & 0 deletions core/Command/Background/JobWorker.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

use OC\Core\Command\InterruptedException;
use OC\Files\SetupManager;
use OCP\BackgroundJob\Events\BeforeJobExecutedEvent;
use OCP\BackgroundJob\Events\JobExecutedEvent;
use OCP\BackgroundJob\IJobList;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\ITempManager;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -25,6 +28,7 @@ public function __construct(
protected LoggerInterface $logger,
private ITempManager $tempManager,
private SetupManager $setupManager,
private IEventDispatcher $eventDispatcher,
) {
parent::__construct($jobList, $logger);
}
Expand Down Expand Up @@ -125,8 +129,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->printJobInfo($job->getId(), $job, $output);
}

$this->eventDispatcher->dispatchTyped(new BeforeJobExecutedEvent($job));
/** @psalm-suppress DeprecatedMethod Calling execute until it is removed, then will switch to start */
$job->execute($this->jobList);
$this->eventDispatcher->dispatchTyped(new JobExecutedEvent($job));

$output->writeln('Job ' . $job->getId() . ' has finished', OutputInterface::VERBOSITY_VERBOSE);

Expand Down
6 changes: 6 additions & 0 deletions cron.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
require_once __DIR__ . '/lib/versioncheck.php';

use OCP\App\IAppManager;
use OCP\BackgroundJob\Events\BeforeJobExecutedEvent;
use OCP\BackgroundJob\Events\JobExecutedEvent;
use OCP\BackgroundJob\IJobList;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\IAppConfig;
use OCP\IConfig;
use OCP\ISession;
Expand Down Expand Up @@ -72,6 +75,7 @@
$logger = Server::get(LoggerInterface::class);
$appConfig = Server::get(IAppConfig::class);
$tempManager = Server::get(ITempManager::class);
$eventDispatcher = Server::get(IEventDispatcher::class);

$tempManager->cleanOld();

Expand Down Expand Up @@ -166,8 +170,10 @@
echo 'Starting job ' . $jobDetails . PHP_EOL;
}

$eventDispatcher->dispatchTyped(new BeforeJobExecutedEvent($job));
/** @psalm-suppress DeprecatedMethod Calling execute until it is removed, then will switch to start */
$job->execute($jobList);
$eventDispatcher->dispatchTyped(new JobExecutedEvent($job));

$timeAfter = time();
$memoryAfter = memory_get_usage();
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@
'OCP\\Authentication\\TwoFactorAuth\\TwoFactorProviderForUserUnregistered' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/TwoFactorProviderForUserUnregistered.php',
'OCP\\Authentication\\TwoFactorAuth\\TwoFactorProviderUserDeleted' => $baseDir . '/lib/public/Authentication/TwoFactorAuth/TwoFactorProviderUserDeleted.php',
'OCP\\AutoloadNotAllowedException' => $baseDir . '/lib/public/AutoloadNotAllowedException.php',
'OCP\\BackgroundJob\\Events\\BeforeJobExecutedEvent' => $baseDir . '/lib/public/BackgroundJob/Events/BeforeJobExecutedEvent.php',
'OCP\\BackgroundJob\\Events\\JobExecutedEvent' => $baseDir . '/lib/public/BackgroundJob/Events/JobExecutedEvent.php',
'OCP\\BackgroundJob\\IJob' => $baseDir . '/lib/public/BackgroundJob/IJob.php',
'OCP\\BackgroundJob\\IJobList' => $baseDir . '/lib/public/BackgroundJob/IJobList.php',
'OCP\\BackgroundJob\\IParallelAwareJob' => $baseDir . '/lib/public/BackgroundJob/IParallelAwareJob.php',
Expand Down
2 changes: 2 additions & 0 deletions lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ class ComposerStaticInit749170dad3f5e7f9ca158f5a9f04f6a2
'OCP\\Authentication\\TwoFactorAuth\\TwoFactorProviderForUserUnregistered' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/TwoFactorProviderForUserUnregistered.php',
'OCP\\Authentication\\TwoFactorAuth\\TwoFactorProviderUserDeleted' => __DIR__ . '/../../..' . '/lib/public/Authentication/TwoFactorAuth/TwoFactorProviderUserDeleted.php',
'OCP\\AutoloadNotAllowedException' => __DIR__ . '/../../..' . '/lib/public/AutoloadNotAllowedException.php',
'OCP\\BackgroundJob\\Events\\BeforeJobExecutedEvent' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/Events/BeforeJobExecutedEvent.php',
'OCP\\BackgroundJob\\Events\\JobExecutedEvent' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/Events/JobExecutedEvent.php',
'OCP\\BackgroundJob\\IJob' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/IJob.php',
'OCP\\BackgroundJob\\IJobList' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/IJobList.php',
'OCP\\BackgroundJob\\IParallelAwareJob' => __DIR__ . '/../../..' . '/lib/public/BackgroundJob/IParallelAwareJob.php',
Expand Down
38 changes: 38 additions & 0 deletions lib/public/BackgroundJob/Events/BeforeJobExecutedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OCP\BackgroundJob\Events;

use OCP\BackgroundJob\IJob;
use OCP\EventDispatcher\Event;

/**
* Emitted before a background job is executed
*
* @since 32.0.0
*/
class BeforeJobExecutedEvent extends Event {

/**
* @since 32.0.0
*/
public function __construct(
private IJob $job,
) {
parent::__construct();
}

/**
* @since 32.0.0
*/
public function getJob(): IJob {
return $this->job;
}

}
38 changes: 38 additions & 0 deletions lib/public/BackgroundJob/Events/JobExecutedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-only
*/

namespace OCP\BackgroundJob\Events;

use OCP\BackgroundJob\IJob;
use OCP\EventDispatcher\Event;

/**
* Emitted before a background job is executed
*
* @since 32.0.0
*/
class JobExecutedEvent extends Event {

/**
* @since 32.0.0
*/
public function __construct(
private IJob $job,
) {
parent::__construct();
}

/**
* @since 32.0.0
*/
public function getJob(): IJob {
return $this->job;
}

}
Loading