mirror of
https://github.com/nextcloud/server.git
synced 2026-06-12 18:21:40 -04:00
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:
parent
8653286107
commit
28004c4b83
2 changed files with 7 additions and 2 deletions
|
|
@ -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 = [];
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue