3 namespace Wallabag\ImportBundle\Command
;
5 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand
;
6 use Symfony\Component\Config\Definition\Exception\Exception
;
7 use Symfony\Component\Console\Input\InputArgument
;
8 use Symfony\Component\Console\Input\InputOption
;
9 use Symfony\Component\Console\Input\InputInterface
;
10 use Symfony\Component\Console\Output\OutputInterface
;
11 use Simpleue\Worker\QueueWorker
;
13 class RedisWorkerCommand
extends ContainerAwareCommand
15 protected function configure()
18 ->setName('wallabag:import:redis-worker')
19 ->setDescription('Launch Redis worker')
20 ->addArgument('serviceName', InputArgument
::REQUIRED
, 'Service to use: wallabag_v1, wallabag_v2, pocket, readability, pinboard, firefox, chrome or instapaper')
21 ->addOption('maxIterations', '', InputOption
::VALUE_OPTIONAL
, 'Number of iterations before stoping', false)
25 protected function execute(InputInterface
$input, OutputInterface
$output)
27 $output->writeln('Worker started at: '.(new \
DateTime())->format('d-m-Y G:i:s'));
28 $output->writeln('Waiting for message ...');
30 $serviceName = $input->getArgument('serviceName');
32 if (!$this->getContainer()->has('wallabag_import.queue.redis.'.$serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.'.$serviceName)) {
33 throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
36 $worker = new QueueWorker(
37 $this->getContainer()->get('wallabag_import.queue.redis.'.$serviceName),
38 $this->getContainer()->get('wallabag_import.consumer.redis.'.$serviceName),
39 $input->getOption('maxIterations')