Skip to content

Commit

Permalink
Merge pull request #3 from sami-evaneos/feat/requeue-on-failure
Browse files Browse the repository at this point in the history
feat: Allow possibility to don't requeueing on failure.
  • Loading branch information
Sami Jnih authored Mar 12, 2018
2 parents c8db720 + e5cce24 commit e310ac9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function getConfigTreeBuilder()
->scalarNode('driver')->end()
->scalarNode('consumer')->end()
->scalarNode('queue')->end()
->scalarNode('requeue_on_failure')->end()
->end()
->end()
->end()
Expand Down
25 changes: 13 additions & 12 deletions src/DependencyInjection/EvaneosBurrowExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

namespace Evaneos\BurrowBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Burrow\Driver\DriverFactory;
use Burrow\CLI\BindCommand;
use Burrow\CLI\DeclareExchangeCommand;
use Burrow\CLI\DeclareQueueCommand;
use Burrow\CLI\DeleteExchangeCommand;
use Burrow\CLI\DeleteQueueCommand;
use Burrow\Driver;
use Burrow\Driver\DriverFactory;
use Burrow\Publisher\AsyncPublisher;
use Symfony\Component\DependencyInjection\Reference;
use Evaneos\Daemon\Worker;
use Symfony\Component\DependencyInjection\Definition;
use Evaneos\BurrowBundle\WorkerFactory;
use Evaneos\Daemon\CLI\DaemonWorkerCommand;
use Burrow\CLI\DeleteExchangeCommand;
use Burrow\CLI\DeclareExchangeCommand;
use Burrow\CLI\DeleteQueueCommand;
use Burrow\CLI\DeclareQueueCommand;
use Burrow\CLI\BindCommand;
use Evaneos\Daemon\Worker;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;

/**
* This is the class that loads and manages your bundle configuration.
Expand Down Expand Up @@ -59,7 +59,8 @@ public function load(array $configs, ContainerBuilder $container)
$definition = new Definition(Worker::class, [
new Reference(sprintf('evaneos_burrow.driver.%s', $value['driver'])),
new Reference($value['consumer']),
$value['queue']
$value['queue'],
$value['requeue_on_failure'],
]);
$definition->setFactory([WorkerFactory::class, 'build']);
$container->setDefinition(sprintf('evaneos_burrow.worker.%s', $name), $definition);
Expand Down
21 changes: 16 additions & 5 deletions src/WorkerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,40 @@

namespace Evaneos\BurrowBundle;

use Burrow\Daemon\QueueHandlingDaemon;
use Burrow\Driver;
use Burrow\QueueConsumer;
use Burrow\Handler\HandlerBuilder;
use Burrow\QueueConsumer;
use Evaneos\Daemon\Worker;
use Burrow\Daemon\QueueHandlingDaemon;

class WorkerFactory
{
/**
* Build a worker.
* Builds a worker.
*
* @param Driver $driver
* @param QueueConsumer $consumer
* @param string $queue
* @param bool $requeueOnFailure
*
* @return Worker
*/
public static function build(Driver $driver, QueueConsumer $consumer, $queue)
public static function build(
Driver $driver,
QueueConsumer $consumer,
$queue,
$requeueOnFailure = true
)
{
$handlerBuilder = new HandlerBuilder($driver);

if ($requeueOnFailure === false) {
$handlerBuilder->doNotRequeueOnFailure();
}

$handler = $handlerBuilder->async()->build($consumer);
$daemon = new QueueHandlingDaemon($driver, $handler, $queue);

return new Worker($daemon);
}
}
}
1 change: 1 addition & 0 deletions tests/app/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ evaneos_burrow:
driver: default
consumer: some_consumer
queue: some_queue
requeue_on_failure: false

services:
some_consumer:
Expand Down

0 comments on commit e310ac9

Please sign in to comment.