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