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