2016-09-09 21:02:03 +02:00
|
|
|
<?php
|
|
|
|
|
|
2023-12-31 09:50:36 +01:00
|
|
|
namespace Wallabag\CoreBundle\Command\Import;
|
2016-09-09 21:02:03 +02:00
|
|
|
|
2017-07-01 09:52:38 +02:00
|
|
|
use Simpleue\Worker\QueueWorker;
|
2016-09-09 21:02:03 +02:00
|
|
|
use Symfony\Component\Config\Definition\Exception\Exception;
|
2022-12-15 20:57:02 +01:00
|
|
|
use Symfony\Component\Console\Command\Command;
|
2016-09-09 21:02:03 +02:00
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
2017-07-01 09:52:38 +02:00
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
2016-09-09 21:02:03 +02:00
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2022-12-15 20:57:02 +01:00
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
2016-09-09 21:02:03 +02:00
|
|
|
|
2022-12-15 20:57:02 +01:00
|
|
|
class RedisWorkerCommand extends Command
|
2016-09-09 21:02:03 +02:00
|
|
|
{
|
2024-02-02 23:24:33 +01:00
|
|
|
protected static $defaultName = 'wallabag:import:redis-worker';
|
|
|
|
|
protected static $defaultDescription = 'Launch Redis worker';
|
|
|
|
|
|
2022-12-15 20:57:02 +01:00
|
|
|
private $container;
|
|
|
|
|
|
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
|
{
|
|
|
|
|
$this->container = $container;
|
|
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-09 21:02:03 +02:00
|
|
|
protected function configure()
|
|
|
|
|
{
|
|
|
|
|
$this
|
2021-02-08 09:08:12 +01:00
|
|
|
->addArgument('serviceName', InputArgument::REQUIRED, 'Service to use: wallabag_v1, wallabag_v2, pocket, readability, pinboard, delicious, firefox, chrome or instapaper')
|
2022-10-03 18:31:43 -06:00
|
|
|
->addOption('maxIterations', '', InputOption::VALUE_OPTIONAL, 'Number of iterations before stopping', false)
|
2016-09-09 21:02:03 +02:00
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
|
{
|
2017-07-01 09:52:38 +02:00
|
|
|
$output->writeln('Worker started at: ' . (new \DateTime())->format('d-m-Y G:i:s'));
|
2016-09-09 21:02:03 +02:00
|
|
|
$output->writeln('Waiting for message ...');
|
|
|
|
|
|
|
|
|
|
$serviceName = $input->getArgument('serviceName');
|
|
|
|
|
|
2024-01-01 17:15:20 +01:00
|
|
|
if (!$this->container->has('wallabag_core.queue.redis.' . $serviceName) || !$this->container->has('wallabag_core.consumer.redis.' . $serviceName)) {
|
2016-09-09 21:02:03 +02:00
|
|
|
throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$worker = new QueueWorker(
|
2024-01-01 17:15:20 +01:00
|
|
|
$this->container->get('wallabag_core.queue.redis.' . $serviceName),
|
|
|
|
|
$this->container->get('wallabag_core.consumer.redis.' . $serviceName),
|
2016-12-06 11:44:40 +01:00
|
|
|
(int) $input->getOption('maxIterations')
|
2016-09-09 21:02:03 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$worker->start();
|
2022-11-23 15:51:33 +01:00
|
|
|
|
|
|
|
|
return 0;
|
2016-09-09 21:02:03 +02:00
|
|
|
}
|
|
|
|
|
}
|