|
8 | 8 | use CodeRhapsodie\DataflowBundle\Factory\ConnectionFactory; |
9 | 9 | use CodeRhapsodie\DataflowBundle\Gateway\JobGateway; |
10 | 10 | use Symfony\Component\Console\Attribute\AsCommand; |
11 | | -use Symfony\Component\Console\Command\Command; |
12 | | -use Symfony\Component\Console\Input\InputInterface; |
13 | | -use Symfony\Component\Console\Input\InputOption; |
14 | | -use Symfony\Component\Console\Output\OutputInterface; |
| 11 | +use Symfony\Component\Console\Attribute\Option; |
15 | 12 | use Symfony\Component\Console\Style\SymfonyStyle; |
16 | 13 |
|
17 | 14 | /** |
|
20 | 17 | #[AsCommand('code-rhapsodie:dataflow:job:show', 'Display job details for schedule or specific job', help: <<<'TXT' |
21 | 18 | The <info>%command.name%</info> display job details for schedule or specific job. |
22 | 19 | TXT)] |
23 | | -class JobShowCommand extends Command |
| 20 | +final readonly class JobShowCommand |
24 | 21 | { |
25 | 22 | private const STATUS_MAPPING = [ |
26 | 23 | Job::STATUS_PENDING => 'Pending', |
27 | 24 | Job::STATUS_RUNNING => 'Running', |
28 | 25 | Job::STATUS_COMPLETED => 'Completed', |
| 26 | + Job::STATUS_QUEUED => 'Queued', |
| 27 | + Job::STATUS_CRASHED => 'Crashed', |
29 | 28 | ]; |
30 | 29 |
|
31 | | - public function __construct(private readonly JobGateway $jobGateway, private readonly ConnectionFactory $connectionFactory) |
| 30 | + public function __construct(private JobGateway $jobGateway, private ConnectionFactory $connectionFactory) |
32 | 31 | { |
33 | | - parent::__construct(); |
34 | 32 | } |
35 | 33 |
|
36 | | - protected function configure(): void |
37 | | - { |
38 | | - $this |
39 | | - ->addOption('job-id', null, InputOption::VALUE_REQUIRED, 'Id of the job to get details') |
40 | | - ->addOption('schedule-id', null, InputOption::VALUE_REQUIRED, 'Id of schedule for last execution details') |
41 | | - ->addOption('details', null, InputOption::VALUE_NONE, 'Display full details') |
42 | | - ->addOption('connection', null, InputOption::VALUE_REQUIRED, 'Define the DBAL connection to use'); |
43 | | - } |
44 | | - |
45 | | - protected function execute(InputInterface $input, OutputInterface $output): int |
46 | | - { |
47 | | - if ($input->getOption('connection') !== null) { |
48 | | - $this->connectionFactory->setConnectionName($input->getOption('connection')); |
| 34 | + public function __invoke( |
| 35 | + SymfonyStyle $io, |
| 36 | + #[Option('Id of the job to get details')] ?int $jobId = null, |
| 37 | + #[Option('Id of schedule for last execution details')] ?int $scheduleId = null, |
| 38 | + #[Option('Display full details')] bool $details = false, |
| 39 | + #[Option('Define the DBAL connection to use')] ?string $connection = null, |
| 40 | + ): int { |
| 41 | + if ($connection !== null) { |
| 42 | + $this->connectionFactory->setConnectionName($connection); |
49 | 43 | } |
50 | 44 |
|
51 | | - $io = new SymfonyStyle($input, $output); |
52 | | - |
53 | | - $jobId = (int) $input->getOption('job-id'); |
54 | | - $scheduleId = (int) $input->getOption('schedule-id'); |
55 | 45 | if ($jobId && $scheduleId) { |
56 | 46 | $io->error('You must use `job-id` OR `schedule-id` option, not the 2 in the same time.'); |
57 | 47 |
|
@@ -85,14 +75,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int |
85 | 75 | ['Errors', \count((array) $job->getExceptions())], |
86 | 76 | ['Status', $this->translateStatus($job->getStatus())], |
87 | 77 | ]; |
88 | | - if ($input->getOption('details')) { |
| 78 | + if ($details) { |
89 | 79 | $display[] = ['Type', $job->getDataflowType()]; |
90 | 80 | $display[] = ['Options', json_encode($job->getOptions(), \JSON_THROW_ON_ERROR)]; |
91 | 81 | $io->section('Summary'); |
92 | 82 | } |
93 | 83 |
|
94 | 84 | $io->table(['Field', 'Value'], $display); |
95 | | - if ($input->getOption('details')) { |
| 85 | + if ($details) { |
96 | 86 | $io->section('Exceptions'); |
97 | 87 | $exceptions = array_map(static fn (string $exception) => substr($exception, 0, 900).'…', $job->getExceptions()); |
98 | 88 |
|
|
0 commit comments