1 | <?php |
||
2 | |||
3 | namespace Tarantool\JobQueue\Console\Command; |
||
4 | |||
5 | use Symfony\Component\Console\Input\InputArgument; |
||
6 | use Symfony\Component\Console\Input\InputInterface; |
||
7 | use Symfony\Component\Console\Output\OutputInterface; |
||
8 | |||
9 | class PutCommand extends Command |
||
10 | { |
||
11 | protected function configure(): void |
||
12 | { |
||
13 | parent::configure(); |
||
14 | |||
15 | $this |
||
16 | ->setName('put') |
||
17 | ->setDescription('Puts a task into the queue') |
||
18 | ->addArgument('json-data', InputArgument::REQUIRED) |
||
19 | ; |
||
20 | } |
||
21 | |||
22 | protected function execute(InputInterface $input, OutputInterface $output): void |
||
23 | { |
||
24 | $json = $input->getArgument('json-data'); |
||
25 | $data = json_decode($json, true); |
||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||
26 | |||
27 | if (!is_array($data)) { |
||
28 | throw new \InvalidArgumentException('Invalid json data.'); |
||
29 | } |
||
30 | |||
31 | $queue = $this->createConfigFactory($input, $output)->createQueue(); |
||
32 | $task = $queue->put($data); |
||
33 | |||
34 | $output->writeln(sprintf( |
||
35 | '<comment>%s</comment> was successfully put to <info>%s</info> (#<comment>%d</comment>).', |
||
36 | json_encode($task->getData()), |
||
37 | $queue->getName(), |
||
38 | $task->getId() |
||
39 | )); |
||
40 | } |
||
41 | } |
||
42 |