diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index ee77d68..3540855 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -58,6 +58,7 @@ public function getConfigTreeBuilder() ->scalarNode('driver')->end() ->scalarNode('consumer')->end() ->scalarNode('queue')->end() + ->scalarNode('requeue_on_failure')->end() ->end() ->end() ->end() diff --git a/src/DependencyInjection/EvaneosBurrowExtension.php b/src/DependencyInjection/EvaneosBurrowExtension.php index e2cbde4..c404989 100644 --- a/src/DependencyInjection/EvaneosBurrowExtension.php +++ b/src/DependencyInjection/EvaneosBurrowExtension.php @@ -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. @@ -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); diff --git a/src/WorkerFactory.php b/src/WorkerFactory.php index 5b89ff0..54196b8 100644 --- a/src/WorkerFactory.php +++ b/src/WorkerFactory.php @@ -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); } -} \ No newline at end of file +} diff --git a/tests/app/config/config.yml b/tests/app/config/config.yml index cc01840..148a777 100644 --- a/tests/app/config/config.yml +++ b/tests/app/config/config.yml @@ -16,6 +16,7 @@ evaneos_burrow: driver: default consumer: some_consumer queue: some_queue + requeue_on_failure: false services: some_consumer: