Files
wallabag/src/Command/Import/RedisWorkerCommand.php

58 lines
2.0 KiB
PHP
Raw Normal View History

<?php
2024-02-19 01:30:12 +01:00
namespace Wallabag\Command\Import;
2017-07-01 09:52:38 +02:00
use Simpleue\Worker\QueueWorker;
use Symfony\Component\Config\Definition\Exception\Exception;
use Symfony\Component\Console\Command\Command;
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;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
class RedisWorkerCommand extends Command
{
2024-02-02 23:24:33 +01:00
protected static $defaultName = 'wallabag:import:redis-worker';
protected static $defaultDescription = 'Launch Redis worker';
private $container;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct();
}
protected function configure()
{
$this
->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)
;
}
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'));
$output->writeln('Waiting for message ...');
$serviceName = $input->getArgument('serviceName');
if (!$this->container->has('wallabag_core.queue.redis.' . $serviceName) || !$this->container->has('wallabag_core.consumer.redis.' . $serviceName)) {
throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
}
$worker = new QueueWorker(
$this->container->get('wallabag_core.queue.redis.' . $serviceName),
$this->container->get('wallabag_core.consumer.redis.' . $serviceName),
(int) $input->getOption('maxIterations')
);
$worker->start();
2022-11-23 15:51:33 +01:00
return 0;
}
}