diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index ca1e22a..86217dd 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -22,6 +22,7 @@ public function getConfigTreeBuilder() $rootNode ->children() + ->scalarNode('worker_count')->defaultValue(1)->end() ->scalarNode('supervisor_instance_identifier')->defaultValue('symfony2')->end() ->end(); $this->addPaths($rootNode); diff --git a/DependencyInjection/RabbitMqSupervisorExtension.php b/DependencyInjection/RabbitMqSupervisorExtension.php index d6ef37d..4012d1b 100644 --- a/DependencyInjection/RabbitMqSupervisorExtension.php +++ b/DependencyInjection/RabbitMqSupervisorExtension.php @@ -24,6 +24,7 @@ public function load(array $configs, ContainerBuilder $container) $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); + $container->setParameter('phobetor_rabbitmq_supervisor.worker_count', $config['worker_count']); $container->setParameter('phobetor_rabbitmq_supervisor.supervisor_instance_identifier', $config['supervisor_instance_identifier']); $container->setParameter('phobetor_rabbitmq_supervisor.paths', $config['paths']); $container->setParameter('phobetor_rabbitmq_supervisor.workspace', $config['paths']['workspace_directory']); diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 709922f..16e3e8d 100644 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -13,6 +13,7 @@ services: - "%phobetor_rabbitmq_supervisor.commands%" - "%phobetor_rabbitmq_supervisor.consumers%" - "%phobetor_rabbitmq_supervisor.multiple_consumers%" + - "%phobetor_rabbitmq_supervisor.worker_count%" phobetor_rabbitmq_supervisor.supervisor_service: class: "%phobetor_rabbitmq_supervisor.supervisor_service.class%" diff --git a/Services/RabbitMqSupervisor.php b/Services/RabbitMqSupervisor.php index 4de36a7..f714f44 100644 --- a/Services/RabbitMqSupervisor.php +++ b/Services/RabbitMqSupervisor.php @@ -44,6 +44,11 @@ class RabbitMqSupervisor */ private $multipleConsumers; + /** + * @var int + */ + private $workerCount; + /** * Initialize Handler * @@ -54,8 +59,9 @@ class RabbitMqSupervisor * @param array $commands * @param array $consumers * @param array $multipleConsumers + * @param int $workerCount */ - public function __construct(Supervisor $supervisor, EngineInterface $templating, $kernelRootDir, array $paths, array $commands, $consumers, $multipleConsumers) + public function __construct(Supervisor $supervisor, EngineInterface $templating, $kernelRootDir, array $paths, array $commands, $consumers, $multipleConsumers, $workerCount) { $this->supervisor = $supervisor; $this->templating = $templating; @@ -64,6 +70,7 @@ public function __construct(Supervisor $supervisor, EngineInterface $templating, $this->commands = $commands; $this->consumers = $consumers; $this->multipleConsumers = $multipleConsumers; + $this->workerCount = $workerCount; } /** @@ -263,7 +270,7 @@ private function generateWorkerConfigurations($names, $command) 'kernelRootDir' => $this->kernelRootDir, 'workerOutputLog' => $this->paths['worker_output_log_file'], 'workerErrorLog' => $this->paths['worker_error_log_file'], - 'numprocs' => 1, + 'numprocs' => $this->workerCount, 'options' => array( 'startsecs' => '2', 'autorestart' => 'true',