wallabag/src/Wallabag/ImportBundle/Command/RedisWorkerCommand.php

47 lines
1.8 KiB
PHP
Raw Normal View History

<?php
namespace Wallabag\ImportBundle\Command;
2017-07-01 07:52:38 +00:00
use Simpleue\Worker\QueueWorker;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Config\Definition\Exception\Exception;
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;
use Symfony\Component\Console\Output\OutputInterface;
class RedisWorkerCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('wallabag:import:redis-worker')
->setDescription('Launch Redis worker')
->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)
;
}
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'));
$output->writeln('Waiting for message ...');
$serviceName = $input->getArgument('serviceName');
2017-07-01 07:52:38 +00:00
if (!$this->getContainer()->has('wallabag_import.queue.redis.' . $serviceName) || !$this->getContainer()->has('wallabag_import.consumer.redis.' . $serviceName)) {
throw new Exception(sprintf('No queue or consumer found for service name: "%s"', $input->getArgument('serviceName')));
}
$worker = new QueueWorker(
2017-07-01 07:52:38 +00:00
$this->getContainer()->get('wallabag_import.queue.redis.' . $serviceName),
$this->getContainer()->get('wallabag_import.consumer.redis.' . $serviceName),
(int) $input->getOption('maxIterations')
);
$worker->start();
2022-11-23 14:51:33 +00:00
return 0;
}
}