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
27 changes: 20 additions & 7 deletions core/Command/Background/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,46 @@ protected function configure(): void {
->addOption(
'class',
'c',
InputOption::VALUE_OPTIONAL,
InputOption::VALUE_REQUIRED,
'Job class to search for',
null
)->addOption(
'limit',
'l',
InputOption::VALUE_OPTIONAL,
InputOption::VALUE_REQUIRED,
'Number of jobs to retrieve',
'500'
)->addOption(
'offset',
'o',
InputOption::VALUE_OPTIONAL,
InputOption::VALUE_REQUIRED,
'Offset for retrieving jobs',
'0'
)
->addOption(
'group',
null,
InputOption::VALUE_NONE,
'Group jobs by class'
)
;
parent::configure();
}

#[\Override]
protected function execute(InputInterface $input, OutputInterface $output): int {
$limit = (int)$input->getOption('limit');
$jobsInfo = $this->formatJobs($this->jobList->getJobsIterator($input->getOption('class'), $limit, (int)$input->getOption('offset')));
$this->writeTableInOutputFormat($input, $output, $jobsInfo);
if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN && count($jobsInfo) >= $limit) {
$output->writeln("\n<comment>Output is currently limited to " . $limit . ' jobs. Specify `-l, --limit[=LIMIT]` to override.</comment>');
$offset = (int)$input->getOption('offset');
$group = $input->getOption('group');
if ($group) {
$grouped = $this->jobList->countByClass($limit, $offset);
$this->writeTableInOutputFormat($input, $output, $grouped);
} else {
$jobsInfo = $this->formatJobs($this->jobList->getJobsIterator($input->getOption('class'), $limit, $offset));
$this->writeTableInOutputFormat($input, $output, $jobsInfo);
if ($input->getOption('output') === self::OUTPUT_FORMAT_PLAIN && count($jobsInfo) >= $limit) {
$output->writeln("\n<comment>Output is currently limited to " . $limit . ' jobs. Specify `-l, --limit[=LIMIT]` to override.</comment>');
}
}
return 0;
}
Expand Down
8 changes: 7 additions & 1 deletion lib/private/BackgroundJob/JobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,13 +422,19 @@ public function hasReservedJob(?string $className = null): bool {
}

#[Override]
public function countByClass(): array {
public function countByClass(?int $limit = null, int $offset = 0): array {
$query = $this->connection->getQueryBuilder();
$query->select('class')
->selectAlias($query->func()->count('id'), 'count')
->from('jobs')
->orderBy('count')
->groupBy('class');
if ($offset > 0) {
$query = $query->setFirstResult($offset);
}
if ($limit !== null) {
$query = $query->setMaxResults($limit);
}

$result = $query->executeQuery();

Expand Down
2 changes: 1 addition & 1 deletion lib/public/BackgroundJob/IJobList.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,5 +173,5 @@ public function hasReservedJob(?string $className): bool;
* @return list<array{class:class-string<IJob>, count:int}>
* @since 30.0.0
*/
public function countByClass(): array;
public function countByClass(?int $limit = null, int $offset = 0): array;
}
Loading