aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/Command/Background/Job.php6
-rw-r--r--core/Command/Background/JobWorker.php6
-rw-r--r--cron.php6
-rw-r--r--lib/composer/composer/autoload_classmap.php2
-rw-r--r--lib/composer/composer/autoload_static.php2
-rw-r--r--lib/public/BackgroundJob/Events/BeforeJobExecutedEvent.php38
-rw-r--r--lib/public/BackgroundJob/Events/JobExecutedEvent.php38
7 files changed, 98 insertions, 0 deletions
diff --git a/core/Command/Background/Job.php b/core/Command/Background/Job.php
index 7fa005cf231..5cea459f177 100644
--- a/core/Command/Background/Job.php
+++ b/core/Command/Background/Job.php
@@ -8,8 +8,11 @@ declare(strict_types=1);
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;
@@ -19,6 +22,7 @@ use Symfony\Component\Console\Output\OutputInterface;
class Job extends Command {
public function __construct(
protected IJobList $jobList,
+ private IEventDispatcher $eventDispatcher,
) {
parent::__construct();
}
@@ -67,8 +71,10 @@ class Job extends Command {
$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())) {
diff --git a/core/Command/Background/JobWorker.php b/core/Command/Background/JobWorker.php
index 8289021887b..401868c93ba 100644
--- a/core/Command/Background/JobWorker.php
+++ b/core/Command/Background/JobWorker.php
@@ -10,7 +10,10 @@ namespace OC\Core\Command\Background;
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;
@@ -25,6 +28,7 @@ class JobWorker extends JobBase {
protected LoggerInterface $logger,
private ITempManager $tempManager,
private SetupManager $setupManager,
+ private IEventDispatcher $eventDispatcher,
) {
parent::__construct($jobList, $logger);
}
@@ -125,8 +129,10 @@ class JobWorker extends JobBase {
$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);
diff --git a/cron.php b/cron.php
index 993faae3cae..fc8ceb10a8d 100644
--- a/cron.php
+++ b/cron.php
@@ -11,7 +11,10 @@ declare(strict_types=1);
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;
@@ -72,6 +75,7 @@ Options:
$logger = Server::get(LoggerInterface::class);
$appConfig = Server::get(IAppConfig::class);
$tempManager = Server::get(ITempManager::class);
+ $eventDispatcher = Server::get(IEventDispatcher::class);
$tempManager->cleanOld();
@@ -166,8 +170,10 @@ Options:
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();
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index 52e3075e413..1588aa58cac 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -180,6 +180,8 @@ return array(
'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',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index e98bc3e1aaa..69c960b94ac 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -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',
diff --git a/lib/public/BackgroundJob/Events/BeforeJobExecutedEvent.php b/lib/public/BackgroundJob/Events/BeforeJobExecutedEvent.php
new file mode 100644
index 00000000000..e0240355e43
--- /dev/null
+++ b/lib/public/BackgroundJob/Events/BeforeJobExecutedEvent.php
@@ -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;
+ }
+
+}
diff --git a/lib/public/BackgroundJob/Events/JobExecutedEvent.php b/lib/public/BackgroundJob/Events/JobExecutedEvent.php
new file mode 100644
index 00000000000..9819cf2762e
--- /dev/null
+++ b/lib/public/BackgroundJob/Events/JobExecutedEvent.php
@@ -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;
+ }
+
+}