diff options
author | Jeremy Benoist <j0k3r@users.noreply.github.com> | 2016-09-19 07:15:40 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-19 07:15:40 +0200 |
commit | da18a4682f124b02278860d23ac1d59dee995277 (patch) | |
tree | eabbe9da7203eea41e0cb0ec3c26b9b6599cf58f /src/Wallabag/ImportBundle/Command | |
parent | 0ed8ce55b5caf2c88e8330afa83abef6c4aac9a4 (diff) | |
parent | 59b97fae996d8307b9d957d210d46200f6d206bf (diff) | |
download | wallabag-da18a4682f124b02278860d23ac1d59dee995277.tar.gz wallabag-da18a4682f124b02278860d23ac1d59dee995277.tar.zst wallabag-da18a4682f124b02278860d23ac1d59dee995277.zip |
Merge pull request #1941 from wallabag/v2-asynchronous-jobs
Use asynchronous jobs for imports
Diffstat (limited to 'src/Wallabag/ImportBundle/Command')
-rw-r--r-- | src/Wallabag/ImportBundle/Command/ImportCommand.php | 6 | ||||
-rw-r--r-- | src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php | 44 |
2 files changed, 49 insertions, 1 deletions
diff --git a/src/Wallabag/ImportBundle/Command/ImportCommand.php b/src/Wallabag/ImportBundle/Command/ImportCommand.php index a4aa8531..20ecc6e1 100644 --- a/src/Wallabag/ImportBundle/Command/ImportCommand.php +++ b/src/Wallabag/ImportBundle/Command/ImportCommand.php | |||
@@ -26,6 +26,10 @@ class ImportCommand extends ContainerAwareCommand | |||
26 | { | 26 | { |
27 | $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); | 27 | $output->writeln('Start : '.(new \DateTime())->format('d-m-Y G:i:s').' ---'); |
28 | 28 | ||
29 | if (!file_exists($input->getArgument('filepath'))) { | ||
30 | throw new Exception(sprintf('File "%s" not found', $input->getArgument('filepath'))); | ||
31 | } | ||
32 | |||
29 | $em = $this->getContainer()->get('doctrine')->getManager(); | 33 | $em = $this->getContainer()->get('doctrine')->getManager(); |
30 | // Turning off doctrine default logs queries for saving memory | 34 | // Turning off doctrine default logs queries for saving memory |
31 | $em->getConnection()->getConfiguration()->setSQLLogger(null); | 35 | $em->getConnection()->getConfiguration()->setSQLLogger(null); |
@@ -43,9 +47,9 @@ class ImportCommand extends ContainerAwareCommand | |||
43 | } | 47 | } |
44 | 48 | ||
45 | $wallabag->setMarkAsRead($input->getOption('markAsRead')); | 49 | $wallabag->setMarkAsRead($input->getOption('markAsRead')); |
50 | $wallabag->setUser($user); | ||
46 | 51 | ||
47 | $res = $wallabag | 52 | $res = $wallabag |
48 | ->setUser($user) | ||
49 | ->setFilepath($input->getArgument('filepath')) | 53 | ->setFilepath($input->getArgument('filepath')) |
50 | ->import(); | 54 | ->import(); |
51 | 55 | ||
diff --git a/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php new file mode 100644 index 00000000..5f90e00f --- /dev/null +++ b/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php | |||
@@ -0,0 +1,44 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\ImportBundle\Command; | ||
4 | |||
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; | ||
12 | |||
13 | class RedisWorkerCommand extends ContainerAwareCommand | ||
14 | { | ||
15 | protected function configure() | ||
16 | { | ||
17 | $this | ||
18 | ->setName('wallabag:import:redis-worker') | ||
19 | ->setDescription('Launch Redis worker') | ||
20 | ->addArgument('serviceName', InputArgument::REQUIRED, 'Service to use: wallabag_v1, wallabag_v2, pocket or readability') | ||
21 | ->addOption('maxIterations', '', InputOption::VALUE_OPTIONAL, 'Number of iterations before stoping', false) | ||
22 | ; | ||
23 | } | ||
24 | |||
25 | protected function execute(InputInterface $input, OutputInterface $output) | ||
26 | { | ||
27 | $output->writeln('Worker started at: '.(new \DateTime())->format('d-m-Y G:i:s')); | ||
28 | $output->writeln('Waiting for message ...'); | ||
29 | |||
30 | $serviceName = $input->getArgument('serviceName'); | ||
31 | |||
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'))); | ||
34 | } | ||
35 | |||
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') | ||
40 | ); | ||
41 | |||
42 | $worker->start(); | ||
43 | } | ||
44 | } | ||