Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions 6 CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Queue Client Bundle Changelog

## v2.0.0

- Use autowire
- Explicitly declare Commands
- [BR] Symfony 3.3 is now required

## v1.1.1

- Remove debug code
Expand Down
37 changes: 15 additions & 22 deletions 37 Command/AddMessagesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,24 @@

namespace ReputationVIP\Bundle\QueueClientBundle\Command;

use Psr\Log\LoggerInterface;
use ReputationVIP\Bundle\QueueClientBundle\Utils\Output;
use ReputationVIP\QueueClient\QueueClientInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

class AddMessagesCommand extends ContainerAwareCommand
class AddMessagesCommand extends Command
{
/**
* @var Output $output
*/
private $output;
/** @var QueueClientInterface */
private $queueClient;

public function __construct(QueueClientInterface $queueClient)
{
parent::__construct();

$this->queueClient = $queueClient;
}

protected function configure()
{
Expand All @@ -27,7 +29,8 @@ protected function configure()
->addOption('priority', 'p', InputOption::VALUE_OPTIONAL, 'Add in queue with specific priority')
->addArgument('queueName', InputArgument::REQUIRED, 'queue')
->addArgument('messages', InputArgument::IS_ARRAY, 'messages to add')
->setHelp('This command add messages in queue.');
->setHelp('This command add messages in queue.')
;
}

/**
Expand All @@ -37,28 +40,18 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
/** @var LoggerInterface $logger */
$logger = $this->getContainer()->get('logger');
} catch (ServiceNotFoundException $e) {
$logger = null;
}
$this->output = new Output($logger, $output);
/** @var QueueClientInterface $queueClient */
$queueClient = $this->getContainer()->get('queue_client');

$priority = null;
if ($input->getOption('priority')) {
$priority = $input->getOption('priority');
if (!in_array($priority, $queueClient->getPriorityHandler()->getAll())) {
if (!in_array($priority, $this->queueClient->getPriorityHandler()->getAll())) {
throw new \InvalidArgumentException('Priority "' . $priority . '" not found.');
}
}

$queueName = $input->getArgument('queueName');
$messages = $input->getArgument('messages');

$queueClient->addMessages($queueName, $messages, $priority);
$this->queueClient->addMessages($queueName, $messages, $priority);

return 0;
}
Expand Down
61 changes: 25 additions & 36 deletions 61 Command/CreateQueuesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
namespace ReputationVIP\Bundle\QueueClientBundle\Command;

use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use ReputationVIP\Bundle\QueueClientBundle\Utils\Output;
use ReputationVIP\Bundle\QueueClientBundle\Configuration\QueuesConfiguration;
use ReputationVIP\QueueClient\QueueClientInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
Expand All @@ -13,15 +11,19 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\Yaml\Yaml;

class CreateQueuesCommand extends ContainerAwareCommand
{
/**
* @var Output $output
*/
private $output;
/** @var QueueClientInterface */
private $queueClient;

public function __construct(QueueClientInterface $queueClient)
{
parent::__construct();

$this->queueClient = $queueClient;
}

protected function configure()
{
Expand All @@ -47,42 +49,44 @@ protected function configure()
}

/**
* @param OutputInterface $output
* @param QueueClientInterface $queueClient
* @param string $fileName
*
* @return int
*/
private function createFromFile($queueClient, $fileName)
private function createFromFile(OutputInterface $output, QueueClientInterface $queueClient, $fileName)
{
try {
$processor = new Processor();
$configuration = new QueuesConfiguration();
$processedConfiguration = $processor->processConfiguration($configuration, Yaml::parse(file_get_contents($fileName)));

} catch (\Exception $e) {
$this->output->write($e->getMessage(), Output::CRITICAL);
$output->writeln($e->getMessage());

return 1;
}
array_walk_recursive($processedConfiguration, 'ReputationVIP\Bundle\QueueClientBundle\QueueClientFactory::resolveParameters', $this->getContainer());
$this->output->write('Start create queue.', Output::INFO);
$output->writeln('Start create queue.');
foreach ($processedConfiguration[QueuesConfiguration::QUEUES_NODE] as $queue) {
$queueName = $queue[QueuesConfiguration::QUEUE_NAME_NODE];
try {
$queueClient->createQueue($queueName);
$this->output->write('Queue ' . $queueName . ' created.', Output::INFO);
$output->writeln('Queue ' . $queueName . ' created.');
} catch (\Exception $e) {
$this->output->write($e->getMessage(), Output::WARNING);
$output->writeln($e->getMessage());
}
foreach ($queue[QueuesConfiguration::QUEUE_ALIASES_NODE] as $alias) {
try {
$queueClient->addAlias($queueName, $alias);
$this->output->write('Queue alias ' . $alias . ' -> ' . $queueName . ' found.', Output::INFO);
$output->writeln('Queue alias ' . $alias . ' -> ' . $queueName . ' found.');
} catch (\Exception $e) {
$this->output->write($e->getMessage(), Output::WARNING);
$output->writeln($e->getMessage());
}
}
}
$this->output->write('End create queue.', Output::INFO);
$output->writeln('End create queue.');

return 0;
}
Expand All @@ -94,34 +98,19 @@ private function createFromFile($queueClient, $fileName)
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
try {
/** @var LoggerInterface $logger */
$logger = $this->getContainer()->get('logger');
} catch (ServiceNotFoundException $e) {
$logger = null;
}
$this->output = new Output($logger, $output);
try {
/** @var QueueClientInterface $queueClient */
$queueClient = $this->getContainer()->get('queue_client');
} catch (ServiceNotFoundException $e) {
$this->output->write('No queue client service found.', Output::CRITICAL);

return 1;
}
if ($input->getOption('file')) {
$fileName = $input->getOption('file');

return $this->createFromFile($queueClient, $fileName);
return $this->createFromFile($output, $this->queueClient, $fileName);
} else {
$queues = $input->getArgument('queues');
if (count($queues)) {
foreach ($queues as $queue) {
try {
$queueClient->createQueue($queue);
$this->output->write('Queue ' . $queue . ' created.', Output::INFO);
$this->queueClient->createQueue($queue);
$output->writeln('Queue ' . $queue . ' created.');
} catch (\Exception $e) {
$this->output->write($e->getMessage(), Output::WARNING);
$output->writeln($e->getMessage());
}
}

Expand All @@ -130,9 +119,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
try {
$fileName = $this->getContainer()->getParameter('queue_client.queues_file');

return $this->createFromFile($queueClient, $fileName);
return $this->createFromFile($output, $this->queueClient, $fileName);
} catch (InvalidArgumentException $e) {
$this->output->write('No queue_client.queues_file parameter found.', Output::CRITICAL);
$output->writeln('No queue_client.queues_file parameter found.');

return 1;
}
Expand Down
59 changes: 24 additions & 35 deletions 59 Command/DeleteQueuesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
namespace ReputationVIP\Bundle\QueueClientBundle\Command;

use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use ReputationVIP\Bundle\QueueClientBundle\Configuration\QueuesConfiguration;
use ReputationVIP\Bundle\QueueClientBundle\Utils\Output;
use ReputationVIP\QueueClient\QueueClientInterface;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Config\Definition\Processor;
Expand All @@ -14,15 +12,19 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
use Symfony\Component\Yaml\Yaml;

class DeleteQueuesCommand extends ContainerAwareCommand
{
/**
* @var Output $output
*/
private $output;
/** @var QueueClientInterface */
private $queueClient;

public function __construct(QueueClientInterface $queueClient)
{
parent::__construct();

$this->queueClient = $queueClient;
}

protected function configure()
{
Expand All @@ -49,34 +51,35 @@ protected function configure()
}

/**
* @param QueueClientInterface $queueClient
* @param OutputInterface $output
* @param string $fileName
*
* @return int
*/
private function deleteFromFile($queueClient, $fileName)
private function deleteFromFile(OutputInterface $output, $fileName)
{
try {
$processor = new Processor();
$configuration = new QueuesConfiguration();
$processedConfiguration = $processor->processConfiguration($configuration, Yaml::parse(file_get_contents($fileName)));

} catch (\Exception $e) {
$this->output->write($e->getMessage(), Output::CRITICAL);
$output->write($e->getMessage());

return 1;
}
array_walk_recursive($processedConfiguration, 'ReputationVIP\Bundle\QueueClientBundle\QueueClientFactory::resolveParameters', $this->getContainer());
$this->output->write('Start delete queue.', Output::INFO);
$output->write('Start delete queue.');
foreach ($processedConfiguration[QueuesConfiguration::QUEUES_NODE] as $queue) {
$queueName = $queue[QueuesConfiguration::QUEUE_NAME_NODE];
try {
$queueClient->deleteQueue($queueName);
$this->output->write('Queue ' . $queueName . ' deleted.', Output::INFO);
$this->queueClient->deleteQueue($queueName);
$output->write('Queue ' . $queueName . ' deleted.');
} catch (\Exception $e) {
$this->output->write($e->getMessage(), Output::WARNING);
$output->write($e->getMessage());
}
}
$this->output->write('End delete queue.', Output::INFO);
$output->write('End delete queue.');

return 0;
}
Expand All @@ -90,29 +93,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$helper = $this->getHelper('question');
$force = $input->getOption('force') ? true : false;
try {
/** @var LoggerInterface $logger */
$logger = $this->getContainer()->get('logger');
} catch (ServiceNotFoundException $e) {
$logger = null;
}
$this->output = new Output($logger, $output);
try {
/** @var QueueClientInterface $queueClient */
$queueClient = $this->getContainer()->get('queue_client');
} catch (ServiceNotFoundException $e) {
$this->output->write('No queue client service found.', Output::CRITICAL);

return 1;
}
if ($input->getOption('file')) {
$fileName = $input->getOption('file');
if (!($force || $helper->ask($input, $output, new ConfirmationQuestion('Delete queues in file "' . $fileName . '"?', false)))) {

return 0;
}

return $this->deleteFromFile($queueClient, $fileName);
return $this->deleteFromFile($output, $fileName);
} else {
$queues = $input->getArgument('queues');
if (count($queues)) {
Expand All @@ -122,10 +111,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
foreach ($queues as $queue) {
try {
$queueClient->deleteQueue($queue);
$this->output->write('Queue ' . $queue . ' deleted.', Output::INFO);
$this->queueClient->deleteQueue($queue);
$output->write('Queue ' . $queue . ' deleted.');
} catch (\Exception $e) {
$this->output->write($e->getMessage(), Output::WARNING);
$output->write($e->getMessage());
}
}

Expand All @@ -138,9 +127,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
return 0;
}

return $this->deleteFromFile($queueClient, $fileName);
return $this->deleteFromFile($output, $fileName);
} catch (InvalidArgumentException $e) {
$this->output->write('No queue_client.queues_file parameter found.', Output::CRITICAL);
$output->write('No queue_client.queues_file parameter found.');

return 1;
}
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.