]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php
Add a real configuration for CS-Fixer
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Command / RedisWorkerCommand.php
CommitLineData
b3437d58
JB
1<?php
2
3namespace Wallabag\ImportBundle\Command;
4
f808b016 5use Simpleue\Worker\QueueWorker;
b3437d58
JB
6use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7use Symfony\Component\Config\Definition\Exception\Exception;
8use Symfony\Component\Console\Input\InputArgument;
9use Symfony\Component\Console\Input\InputInterface;
f808b016 10use Symfony\Component\Console\Input\InputOption;
b3437d58 11use Symfony\Component\Console\Output\OutputInterface;
b3437d58
JB
12
13class RedisWorkerCommand extends ContainerAwareCommand
14{
15 protected function configure()
16 {
17 $this
18 ->setName('wallabag:import:redis-worker')
19 ->setDescription('Launch Redis worker')
9ab024b4 20 ->addArgument('serviceName', InputArgument::REQUIRED, 'Service to use: wallabag_v1, wallabag_v2, pocket, readability, pinboard, firefox, chrome or instapaper')
015c7a83 21 ->addOption('maxIterations', '', InputOption::VALUE_OPTIONAL, 'Number of iterations before stoping', false)
b3437d58
JB
22 ;
23 }
24
25 protected function execute(InputInterface $input, OutputInterface $output)
26 {
f808b016 27 $output->writeln('Worker started at: ' . (new \DateTime())->format('d-m-Y G:i:s'));
b3437d58
JB
28 $output->writeln('Waiting for message ...');
29
30 $serviceName = $input->getArgument('serviceName');
31
f808b016 32 if (!$this->getContainer()->has('wallabag_import.queue.redis.' . $serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.' . $serviceName)) {
b3437d58
JB
33 throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
34 }
35
36 $worker = new QueueWorker(
f808b016
JB
37 $this->getContainer()->get('wallabag_import.queue.redis.' . $serviceName),
38 $this->getContainer()->get('wallabag_import.consumer.redis.' . $serviceName),
7dc48ef8 39 (int) $input->getOption('maxIterations')
b3437d58
JB
40 );
41
42 $worker->start();
43 }
44}