feat(BackgroundJob): Add $class arg to JobList::countByClass

This allow to only count the jobs for a given class.

Signed-off-by: Louis Chemineau <louis@chmn.me>
This commit is contained in:
Louis Chemineau 2025-06-18 17:22:32 +02:00
parent 8653286107
commit 28004c4b83
No known key found for this signature in database
2 changed files with 7 additions and 2 deletions

View file

@ -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 = [];

View file

@ -164,8 +164,9 @@ interface IJobList {
/**
* Returns a count of jobs per Job class
*
* @param class-string<IJob>|null $class
* @return list<array{class:class-string, count:int}>
* @since 30.0.0
*/
public function countByClass(): array;
public function countByClass(?string $class = null): array;
}