Skip to content

Commit

Permalink
Merge pull request #42 from N-M/command-deprication
Browse files Browse the repository at this point in the history
fixed container aware command depreciation
  • Loading branch information
trandangtri authored Feb 19, 2020
2 parents 42fa14c + 89c7ffc commit f1af721
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 98 deletions.
17 changes: 10 additions & 7 deletions Command/QueueAttrCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

namespace TriTran\SqsQueueBundle\Command;

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\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use TriTran\SqsQueueBundle\Service\QueueManager;

/**
* Class QueueAttrCommand
* @package TriTran\SqsQueueBundle\Command
* Class QueueAttrCommand.
*/
class QueueAttrCommand extends ContainerAwareCommand
class QueueAttrCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function configure()
{
Expand All @@ -31,7 +34,7 @@ protected function configure()
}

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -41,7 +44,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io->title(sprintf('Start getting the attributes of queue URL <comment>%s</comment>', $queueUrl));

/** @var QueueManager $queueManager */
$queueManager = $this->getContainer()->get('tritran.sqs_queue.queue_manager');
$queueManager = $this->container->get('tritran.sqs_queue.queue_manager');
$result = $queueManager->getQueueAttributes($queueUrl);
$io->table(['Attribute Name', 'Value'], array_map(function ($k, $v) {
return [$k, $v];
Expand Down
21 changes: 12 additions & 9 deletions Command/QueueCreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

namespace TriTran\SqsQueueBundle\Command;

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\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use TriTran\SqsQueueBundle\Service\QueueManager;

/**
* Class QueueCreateCommand
* @package TriTran\SqsQueueBundle\Command
* Class QueueCreateCommand.
*/
class QueueCreateCommand extends ContainerAwareCommand
class QueueCreateCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function configure()
{
Expand Down Expand Up @@ -73,27 +76,27 @@ protected function configure()
}

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$queueName = $input->getArgument('name');
if ($this->getContainer()->has(sprintf('tritran.sqs_queue.%s', $queueName))) {
if ($this->container->has(sprintf('tritran.sqs_queue.%s', $queueName))) {
throw new \InvalidArgumentException(sprintf('Queue [%s] exists. Please use another name.', $queueName));
}

$io = new SymfonyStyle($input, $output);
$io->title(sprintf('Start creating a new queue which name is <comment>%s</comment>', $queueName));

/** @var QueueManager $queueManager */
$queueManager = $this->getContainer()->get('tritran.sqs_queue.queue_manager');
$queueManager = $this->container->get('tritran.sqs_queue.queue_manager');
$queueUrl = $queueManager->createQueue($queueName, [
'DelaySeconds' => $input->getOption('delay_seconds'),
'MaximumMessageSize' => $input->getOption('maximum_message_size'),
'MessageRetentionPeriod' => $input->getOption('message_retention_period'),
'ReceiveMessageWaitTimeSeconds' => $input->getOption('receive_message_wait_time_seconds'),
'VisibilityTimeout' => $input->getOption('visibility_timeout'),
'ContentBasedDeduplication' => $input->getOption('content_based_deduplication')
'ContentBasedDeduplication' => $input->getOption('content_based_deduplication'),
]);

$io->text(sprintf('Created successfully. New Queue URL: <comment>%s</comment>', $queueUrl));
Expand Down
18 changes: 11 additions & 7 deletions Command/QueueDeleteCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

namespace TriTran\SqsQueueBundle\Command;

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\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use TriTran\SqsQueueBundle\Service\QueueManager;

/**
* Class QueueDeleteCommand
* @package TriTran\SqsQueueBundle\Command
* Class QueueDeleteCommand.
*/
class QueueDeleteCommand extends ContainerAwareCommand
class QueueDeleteCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function configure()
{
Expand All @@ -38,14 +41,15 @@ protected function configure()
}

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
if (!$input->getOption('force')) {
$io->note('Option --force is mandatory to drop data.');
$io->warning('This action should not be used in the production environment.');

return;
}

Expand All @@ -54,7 +58,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$io->title(sprintf('Start deleting the specified queue by URL <comment>%s</comment>', $queueUrl));

/** @var QueueManager $queueManager */
$queueManager = $this->getContainer()->get('tritran.sqs_queue.queue_manager');
$queueManager = $this->container->get('tritran.sqs_queue.queue_manager');
$queueManager->deleteQueue($queueUrl);

$io->text('Deleted successfully');
Expand Down
17 changes: 10 additions & 7 deletions Command/QueueListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

namespace TriTran\SqsQueueBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use TriTran\SqsQueueBundle\Service\QueueManager;

/**
* Class QueueListCommand
* @package TriTran\SqsQueueBundle\Command
* Class QueueListCommand.
*/
class QueueListCommand extends ContainerAwareCommand
class QueueListCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function configure()
{
Expand All @@ -33,15 +36,15 @@ protected function configure()
}

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->title('Start getting the list of existing queues in SQS');

/** @var QueueManager $queueManager */
$queueManager = $this->getContainer()->get('tritran.sqs_queue.queue_manager');
$queueManager = $this->container->get('tritran.sqs_queue.queue_manager');
$result = $queueManager->listQueue($input->getOption('prefix'));

if (empty($result)) {
Expand Down
19 changes: 11 additions & 8 deletions Command/QueuePingCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,24 @@

namespace TriTran\SqsQueueBundle\Command;

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\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use TriTran\SqsQueueBundle\Service\BaseQueue;

/**
* Class QueuePingCommand
* @package TriTran\SqsQueueBundle\Command
* Class QueuePingCommand.
*/
class QueuePingCommand extends ContainerAwareCommand
class QueuePingCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function configure()
{
Expand All @@ -31,20 +34,20 @@ protected function configure()
}

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$queueName = $input->getArgument('name');
if (!$this->getContainer()->has(sprintf('tritran.sqs_queue.%s', $queueName))) {
if (!$this->container->has(sprintf('tritran.sqs_queue.%s', $queueName))) {
throw new \InvalidArgumentException(sprintf('Queue [%s] does not exist.', $queueName));
}

$io = new SymfonyStyle($input, $output);
$io->title(sprintf('Start sending a Hello message to SQS <comment>%s</comment>', $queueName));

/** @var BaseQueue $queue */
$queue = $this->getContainer()->get(sprintf('tritran.sqs_queue.%s', $queueName));
$queue = $this->container->get(sprintf('tritran.sqs_queue.%s', $queueName));
$messageId = $queue->ping();

$io->text(sprintf('Sent successfully. MessageID: <comment>%s</comment>', $messageId));
Expand Down
20 changes: 12 additions & 8 deletions Command/QueuePurgeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@

namespace TriTran\SqsQueueBundle\Command;

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\Console\Style\SymfonyStyle;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use TriTran\SqsQueueBundle\Service\BaseQueue;

/**
* Class QueuePurgeCommand
* @package TriTran\SqsQueueBundle\Command
* Class QueuePurgeCommand.
*/
class QueuePurgeCommand extends ContainerAwareCommand
class QueuePurgeCommand extends Command implements ContainerAwareInterface
{
use ContainerAwareTrait;

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function configure()
{
Expand All @@ -38,7 +41,7 @@ protected function configure()
}

/**
* @inheritDoc
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
Expand All @@ -47,18 +50,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
if (!$input->getOption('force')) {
$io->note('Option --force is mandatory to drop data.');
$io->warning('This action should not be used in the production environment.');

return;
}

$queueName = $input->getArgument('name');
if (!$this->getContainer()->has(sprintf('tritran.sqs_queue.%s', $queueName))) {
if (!$this->container->has(sprintf('tritran.sqs_queue.%s', $queueName))) {
throw new \InvalidArgumentException(sprintf('Queue [%s] does not exist.', $queueName));
}

$io->title(sprintf('Start purge all your message in SQS <comment>%s</comment>', $queueName));

/** @var BaseQueue $queue */
$queue = $this->getContainer()->get(sprintf('tritran.sqs_queue.%s', $queueName));
$queue = $this->container->get(sprintf('tritran.sqs_queue.%s', $queueName));
$queue->purge();

$io->text('All message in your specified queue were removed successfully');
Expand Down
Loading

0 comments on commit f1af721

Please sign in to comment.