Skip to content

Commit

Permalink
Move debug into the driver
Browse files Browse the repository at this point in the history
  • Loading branch information
gggeek committed Sep 1, 2015
1 parent aaeefab commit ad0cd35
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 19 deletions.
5 changes: 5 additions & 0 deletions Adapter/DriverInterface.php
Expand Up @@ -44,4 +44,9 @@ public function decodeMessage($msg);
* @return \Kaliop\QueueingBundle\Queue\QueueManagerInterface
*/
public function getQueueManager($queueName);

/**
* @param bool $debug
*/
public function setDebug($debug);
}
11 changes: 11 additions & 0 deletions Adapter/RabbitMq/Driver.php
Expand Up @@ -46,4 +46,15 @@ public function getQueueManager($queueName)
$mgr->setQueueName($queueName);
return $mgr;
}

/**
* @param bool $debug
* @todo emit a warning if AMQP_DEBUG is already defined
*/
public function setDebug($debug)
{
if (defined('AMQP_DEBUG') === false) {
define('AMQP_DEBUG', (bool)$debug);
}
}
}
4 changes: 0 additions & 4 deletions Command/ManageDriverCommand.php
Expand Up @@ -35,10 +35,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setOutput($output);

if (defined('AMQP_DEBUG') === false) {
define('AMQP_DEBUG', (bool)$input->getOption('debug'));
}

$driverName = $input->getOption('driver');
$command = $input->getArgument('action');

Expand Down
8 changes: 4 additions & 4 deletions Command/ManageQueueCommand.php
Expand Up @@ -36,15 +36,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setOutput($output);

if (defined('AMQP_DEBUG') === false) {
define('AMQP_DEBUG', (bool)$input->getOption('debug'));
}

$driverName = $input->getOption('driver');
$command = $input->getArgument('action');
$queue = $input->getArgument('queue_name');
$debug = $input->getOption('debug');

$driver = $this->getContainer()->get('kaliop_queueing.driverManager')->getDriver($driverName);
if ($debug !== null) {
$driver->setDebug($debug);
}
$queueManager = $driver->getQueueManager($queue);

if ($command == 'help') {
Expand Down
13 changes: 7 additions & 6 deletions Command/QueueConsoleCommandCommand.php
Expand Up @@ -49,15 +49,13 @@ protected function execute(InputInterface $input, OutputInterface $output)
}
}

/// @todo move into the driver
if (defined('AMQP_DEBUG') === false) {
define('AMQP_DEBUG', (bool)$input->getOption('debug'));
}

$driverName = $input->getOption('driver');
$queue = $input->getArgument('queue_name');
$key = $input->getOption('routing-key');
$ttl = $ttl = $input->getOption('ttl');
$debug = $input->getOption('debug');
$arguments = $input->getArgument('argument/option');

// parse arguments to tell options apart
$options = array();
foreach ($arguments as $key => $arg) {
Expand All @@ -69,6 +67,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$driver = $this->getContainer()->get('kaliop_queueing.driverManager')->getDriver($driverName);
if ($debug !== null) {
$driver->setDebug($debug);
}
$messageProducer = $this->getContainer()->get('kaliop_queueing.message_producer.console_command');
$messageProducer->setDriver($driver);
$messageProducer->setQueueName($queue);
Expand All @@ -78,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$arguments,
$options,
$key,
$ttl = $input->getOption('ttl')
$ttl
);

$this->writeln("Command queued for execution" . ($ttl ? ", will be valid for $ttl seconds" : ''));
Expand Down
9 changes: 4 additions & 5 deletions Command/QueueGenericMessageCommand.php
Expand Up @@ -42,20 +42,19 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$this->setOutput($output);

/// @todo move into the driver
if (defined('AMQP_DEBUG') === false) {
define('AMQP_DEBUG', (bool)$input->getOption('debug'));
}

$driverName = $input->getOption('driver');
$queue = $input->getArgument('queue_name');
$message = $input->getArgument('message');
$contentType = $input->getOption('content-type');
$key = $input->getOption('routing-key');
$repeat = $input->getOption('repeat');
$ttl = $input->getOption('ttl');
$debug = $input->getOption('debug');

$driver = $this->getContainer()->get('kaliop_queueing.driverManager')->getDriver($driverName);
if ($debug !== null) {
$driver->setDebug($debug);
}
$messageProducer = $this->getContainer()->get('kaliop_queueing.message_producer.generic_message');
$messageProducer->setDriver($driver);
$messageProducer->setQueueName($queue);
Expand Down

0 comments on commit ad0cd35

Please sign in to comment.