From 28004c4b8309bee5325e5e88de40965cf5f0a96d Mon Sep 17 00:00:00 2001 From: Louis Chemineau Date: Wed, 18 Jun 2025 17:22:32 +0200 Subject: [PATCH] feat(BackgroundJob): Add `$class` arg to `JobList::countByClass` This allow to only count the jobs for a given class. Signed-off-by: Louis Chemineau --- lib/private/BackgroundJob/JobList.php | 6 +++++- lib/public/BackgroundJob/IJobList.php | 3 ++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/private/BackgroundJob/JobList.php b/lib/private/BackgroundJob/JobList.php index 0d88200cff7..98f103622a1 100644 --- a/lib/private/BackgroundJob/JobList.php +++ b/lib/private/BackgroundJob/JobList.php @@ -417,7 +417,7 @@ class JobList implements IJobList { } } - public function countByClass(): array { + public function countByClass(?string $class = null): array { $query = $this->connection->getQueryBuilder(); $query->select('class') ->selectAlias($query->func()->count('id'), 'count') @@ -425,6 +425,10 @@ class JobList implements IJobList { ->orderBy('count') ->groupBy('class'); + if ($class !== null) { + $query->where($query->expr()->eq('class', $query->createNamedParameter($class))); + } + $result = $query->executeQuery(); $jobs = []; diff --git a/lib/public/BackgroundJob/IJobList.php b/lib/public/BackgroundJob/IJobList.php index c082ef22f2f..20c3caac3ff 100644 --- a/lib/public/BackgroundJob/IJobList.php +++ b/lib/public/BackgroundJob/IJobList.php @@ -164,8 +164,9 @@ interface IJobList { /** * Returns a count of jobs per Job class * + * @param class-string|null $class * @return list * @since 30.0.0 */ - public function countByClass(): array; + public function countByClass(?string $class = null): array; }