setName('background-job:list') ->setDescription('List background jobs') ->addOption( 'class', 'c', InputOption::VALUE_OPTIONAL, 'Job class to search for', null )->addOption( 'limit', 'l', InputOption::VALUE_OPTIONAL, 'Number of jobs to retrieve', '500' )->addOption( 'offset', 'o', InputOption::VALUE_OPTIONAL, 'Offset for retrieving jobs', '0' ) ; parent::configure(); } 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("\nOutput is currently limited to " . $limit . ' jobs. Specify `-l, --limit[=LIMIT]` to override.'); } return 0; } protected function formatJobs(iterable $jobs): array { $jobsInfo = []; foreach ($jobs as $job) { $jobsInfo[] = [ 'id' => $job->getId(), 'class' => get_class($job), 'last_run' => date(DATE_ATOM, $job->getLastRun()), 'argument' => json_encode($job->getArgument()), ]; } return $jobsInfo; } }