49 lines
1.4 KiB
PHP
49 lines
1.4 KiB
PHP
<?php
|
|
namespace Incoviba\Command\Job;
|
|
|
|
use Symfony\Component\Console;
|
|
use Incoviba\Service;
|
|
|
|
#[Console\Attribute\AsCommand(name: 'jobs:pending', description: 'List pending jobs')]
|
|
class Pending extends Console\Command\Command
|
|
{
|
|
public function __construct(protected Service\Job $jobService, ?string $name = null)
|
|
{
|
|
parent::__construct($name);
|
|
}
|
|
|
|
protected function configure(): void
|
|
{
|
|
$this->addOption('full', 'f', Console\Input\InputOption::VALUE_NONE, 'Full output');
|
|
}
|
|
|
|
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
|
|
{
|
|
$jobs = $this->jobService->getPending();
|
|
$jobCount = count($jobs);
|
|
$output->writeln("Found {$jobCount} pending jobs");
|
|
|
|
if ($input->getOption('full') and $jobCount > 0) {
|
|
$io = new Console\Style\SymfonyStyle($input, $output);
|
|
|
|
$rows = [];
|
|
foreach ($jobs as $job) {
|
|
$retries = $job['retries'] ?? 0;
|
|
$updated = $job['updated_at'] ?? '';
|
|
|
|
$rows[] = [
|
|
$job['id'],
|
|
$job['created_at'],
|
|
$job['configuration']['type'],
|
|
$retries,
|
|
$updated
|
|
];
|
|
}
|
|
|
|
$io->table(['ID', 'Created', 'Type', 'Retries', 'Updated'], $rows);
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|