From f7bbf55fe9fa9c30a49780ffaf8cbbfd888ab89f Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 15 Dec 2018 22:34:14 +0200 Subject: [PATCH 1/5] [async-command] Remove command subsriber interface. remove services.yaml --- .../AsyncCommandExtension.php | 25 +++++++++---------- .../Resources/config/services.yml | 7 ------ pkg/async-command/RunCommandProcessor.php | 13 +--------- 3 files changed, 13 insertions(+), 32 deletions(-) delete mode 100644 pkg/async-command/Resources/config/services.yml diff --git a/pkg/async-command/DependencyInjection/AsyncCommandExtension.php b/pkg/async-command/DependencyInjection/AsyncCommandExtension.php index 3d614b4c2..b4005ab28 100644 --- a/pkg/async-command/DependencyInjection/AsyncCommandExtension.php +++ b/pkg/async-command/DependencyInjection/AsyncCommandExtension.php @@ -2,28 +2,27 @@ namespace Enqueue\AsyncCommand\DependencyInjection; +use Enqueue\AsyncCommand\Commands; use Enqueue\AsyncCommand\RunCommandProcessor; -use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; -use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; class AsyncCommandExtension extends Extension { - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container) { - $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); - $loader->load('services.yml'); - - $service = $container->register('enqueue.async_command.run_command_processor', RunCommandProcessor::class) - ->addArgument('%kernel.project_dir%') - ; - foreach ($configs['clients'] as $client) { - $service->addTag('enqueue.command_subscriber', ['client' => $client]); + $id = sprintf('enqueue.async_command.%s.run_command_processor', $client); + $container->register($id, RunCommandProcessor::class) + ->addArgument('%kernel.project_dir%') + ->addTag('enqueue.processor', [ + 'client' => $client, + 'command' => Commands::RUN_COMMAND, + 'queue' => Commands::RUN_COMMAND, + 'queue_prefixed' => false, + 'exclusive' => true, + ]) + ; } } } diff --git a/pkg/async-command/Resources/config/services.yml b/pkg/async-command/Resources/config/services.yml deleted file mode 100644 index 84ada4226..000000000 --- a/pkg/async-command/Resources/config/services.yml +++ /dev/null @@ -1,7 +0,0 @@ -services: - enqueue.async_command.run_command_processor: - class: 'Enqueue\AsyncCommand\RunCommandProcessor' - arguments: - - '%kernel.project_dir%' - tags: - - { name: 'enqueue.command_subscriber', client: 'default' } diff --git a/pkg/async-command/RunCommandProcessor.php b/pkg/async-command/RunCommandProcessor.php index b093adc5c..7925d658c 100644 --- a/pkg/async-command/RunCommandProcessor.php +++ b/pkg/async-command/RunCommandProcessor.php @@ -2,7 +2,6 @@ namespace Enqueue\AsyncCommand; -use Enqueue\Client\CommandSubscriberInterface; use Enqueue\Consumption\Result; use Interop\Queue\Context; use Interop\Queue\Message; @@ -10,7 +9,7 @@ use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; -final class RunCommandProcessor implements Processor, CommandSubscriberInterface +final class RunCommandProcessor implements Processor { /** * @var string @@ -42,16 +41,6 @@ public function process(Message $message, Context $context): Result return Result::ack(); } - public static function getSubscribedCommand(): array - { - return [ - 'command' => Commands::RUN_COMMAND, - 'queue' => Commands::RUN_COMMAND, - 'prefix_queue' => false, - 'exclusive' => true, - ]; - } - /** * @return string */ From 88092173c85f279df742617a7861f37d33818eee Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 15 Dec 2018 22:34:44 +0200 Subject: [PATCH 2/5] [async-events] Remove command subscriber interface. --- pkg/async-event-dispatcher/AsyncProcessor.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pkg/async-event-dispatcher/AsyncProcessor.php b/pkg/async-event-dispatcher/AsyncProcessor.php index 3f5780734..c89f7e1de 100644 --- a/pkg/async-event-dispatcher/AsyncProcessor.php +++ b/pkg/async-event-dispatcher/AsyncProcessor.php @@ -2,14 +2,13 @@ namespace Enqueue\AsyncEventDispatcher; -use Enqueue\Client\CommandSubscriberInterface; use Enqueue\Consumption\Result; use Interop\Queue\Context; use Interop\Queue\Message; use Interop\Queue\Processor; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -class AsyncProcessor implements Processor, CommandSubscriberInterface +class AsyncProcessor implements Processor { /** * @var Registry @@ -51,9 +50,4 @@ public function process(Message $message, Context $context) return self::ACK; } - - public static function getSubscribedCommand() - { - return Commands::DISPATCH_ASYNC_EVENTS; - } } From 214a5a65566f031a878384132eabdd5b2e66652e Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 15 Dec 2018 22:46:41 +0200 Subject: [PATCH 3/5] add transport processor tag. --- .../AsyncCommandExtension.php | 1 + .../AsyncEventDispatcherExtension.php | 18 +++++++++++++++--- .../Resources/config/services.yml | 14 -------------- 3 files changed, 16 insertions(+), 17 deletions(-) diff --git a/pkg/async-command/DependencyInjection/AsyncCommandExtension.php b/pkg/async-command/DependencyInjection/AsyncCommandExtension.php index b4005ab28..9bf17a124 100644 --- a/pkg/async-command/DependencyInjection/AsyncCommandExtension.php +++ b/pkg/async-command/DependencyInjection/AsyncCommandExtension.php @@ -22,6 +22,7 @@ public function load(array $configs, ContainerBuilder $container) 'queue_prefixed' => false, 'exclusive' => true, ]) + ->addTag('enqueue.transport.processor') ; } } diff --git a/pkg/async-event-dispatcher/DependencyInjection/AsyncEventDispatcherExtension.php b/pkg/async-event-dispatcher/DependencyInjection/AsyncEventDispatcherExtension.php index b2ec12fad..8cb79ee98 100644 --- a/pkg/async-event-dispatcher/DependencyInjection/AsyncEventDispatcherExtension.php +++ b/pkg/async-event-dispatcher/DependencyInjection/AsyncEventDispatcherExtension.php @@ -2,17 +2,17 @@ namespace Enqueue\AsyncEventDispatcher\DependencyInjection; +use Enqueue\AsyncEventDispatcher\AsyncProcessor; +use Enqueue\AsyncEventDispatcher\Commands; use Symfony\Component\Config\FileLocator; use Symfony\Component\DependencyInjection\Alias; use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Extension\Extension; use Symfony\Component\DependencyInjection\Loader\YamlFileLoader; +use Symfony\Component\DependencyInjection\Reference; class AsyncEventDispatcherExtension extends Extension { - /** - * {@inheritdoc} - */ public function load(array $configs, ContainerBuilder $container) { $config = $this->processConfiguration(new Configuration(), $configs); @@ -21,5 +21,17 @@ public function load(array $configs, ContainerBuilder $container) $loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); $loader->load('services.yml'); + + $container->register('enqueue.events.async_processor', AsyncProcessor::class) + ->addArgument(new Reference('enqueue.events.registry')) + ->addArgument(new Reference('enqueue.events.event_dispatcher')) + ->addTag('enqueue.processor', [ + 'command' => Commands::DISPATCH_ASYNC_EVENTS, + 'queue' => '%enqueue_events_queue%', + 'queue_prefixed' => false, + 'exclusive' => true, + ]) + ->addTag('enqueue.transport.processor') + ; } } diff --git a/pkg/async-event-dispatcher/Resources/config/services.yml b/pkg/async-event-dispatcher/Resources/config/services.yml index 81ae3f305..2cef52714 100644 --- a/pkg/async-event-dispatcher/Resources/config/services.yml +++ b/pkg/async-event-dispatcher/Resources/config/services.yml @@ -25,20 +25,6 @@ services: - '@event_dispatcher' - '@enqueue.events.async_listener' - enqueue.events.async_processor: - class: 'Enqueue\AsyncEventDispatcher\AsyncProcessor' - public: public - arguments: - - '@enqueue.events.registry' - - '@enqueue.events.event_dispatcher' - tags: - - - name: 'enqueue.processor' - command: 'symfony.dispatch_async_events' - queue: '%enqueue_events_queue%' - queue_prefixed: false - exclusive: true - enqueue.events.php_serializer_event_transofrmer: class: 'Enqueue\AsyncEventDispatcher\PhpSerializerEventTransformer' public: public From f5117c5b5f81fd3f91a20ad2fa8d3f17e110a263 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Sat, 15 Dec 2018 22:53:01 +0200 Subject: [PATCH 4/5] remove not needed tests. --- .../Tests/RunCommandProcessorTest.php | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/pkg/async-command/Tests/RunCommandProcessorTest.php b/pkg/async-command/Tests/RunCommandProcessorTest.php index ce5dc9e4c..83274e2c0 100644 --- a/pkg/async-command/Tests/RunCommandProcessorTest.php +++ b/pkg/async-command/Tests/RunCommandProcessorTest.php @@ -2,9 +2,7 @@ namespace Enqueue\AsyncCommand\Tests; -use Enqueue\AsyncCommand\Commands; use Enqueue\AsyncCommand\RunCommandProcessor; -use Enqueue\Client\CommandSubscriberInterface; use Interop\Queue\Processor; use PHPUnit\Framework\TestCase; @@ -17,13 +15,6 @@ public function testShouldImplementProcessorInterface() $this->assertTrue($rc->implementsInterface(Processor::class)); } - public function testShouldImplementCommandSubscriberInterfaceInterface() - { - $rc = new \ReflectionClass(RunCommandProcessor::class); - - $this->assertTrue($rc->implementsInterface(CommandSubscriberInterface::class)); - } - public function testShouldBeFinal() { $rc = new \ReflectionClass(RunCommandProcessor::class); @@ -37,16 +28,4 @@ public function testCouldBeConstructedWithProjectDirAsFirstArgument() $this->assertAttributeSame('aProjectDir', 'projectDir', $processor); } - - public function testShouldSubscribeOnRunCommand() - { - $subscription = RunCommandProcessor::getSubscribedCommand(); - - $this->assertSame([ - 'command' => Commands::RUN_COMMAND, - 'queue' => Commands::RUN_COMMAND, - 'prefix_queue' => false, - 'exclusive' => true, - ], $subscription); - } } From f3fec660f36a271ab3feab9a1f2a704bd6185f63 Mon Sep 17 00:00:00 2001 From: Maksim Kotlyar Date: Mon, 17 Dec 2018 13:23:18 +0200 Subject: [PATCH 5/5] fix tests. --- .../Tests/Functional/App/config/config.yml | 4 ++++ .../Functional/Events/AsyncProcessorTest.php | 10 +++++----- .../Tests/Functional/RoutesCommandTest.php | 20 +++++++++---------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml b/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml index 718990333..1198e60d2 100644 --- a/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml +++ b/pkg/enqueue-bundle/Tests/Functional/App/config/config.yml @@ -75,6 +75,10 @@ services: alias: 'enqueue.client.routes_command' public: true + test.enqueue.events.async_processor: + alias: 'enqueue.events.async_processor' + public: true + test_async_listener: class: 'Enqueue\Bundle\Tests\Functional\App\TestAsyncListener' public: true diff --git a/pkg/enqueue-bundle/Tests/Functional/Events/AsyncProcessorTest.php b/pkg/enqueue-bundle/Tests/Functional/Events/AsyncProcessorTest.php index 101e5ecec..e595414ae 100644 --- a/pkg/enqueue-bundle/Tests/Functional/Events/AsyncProcessorTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/Events/AsyncProcessorTest.php @@ -33,7 +33,7 @@ public function setUp() public function testCouldBeGetFromContainerAsService() { /** @var AsyncProcessor $processor */ - $processor = static::$container->get('enqueue.events.async_processor'); + $processor = static::$container->get('test.enqueue.events.async_processor'); $this->assertInstanceOf(AsyncProcessor::class, $processor); } @@ -41,7 +41,7 @@ public function testCouldBeGetFromContainerAsService() public function testShouldRejectIfMessageDoesNotContainEventNameProperty() { /** @var AsyncProcessor $processor */ - $processor = static::$container->get('enqueue.events.async_processor'); + $processor = static::$container->get('test.enqueue.events.async_processor'); $message = new NullMessage(); @@ -51,7 +51,7 @@ public function testShouldRejectIfMessageDoesNotContainEventNameProperty() public function testShouldRejectIfMessageDoesNotContainTransformerNameProperty() { /** @var AsyncProcessor $processor */ - $processor = static::$container->get('enqueue.events.async_processor'); + $processor = static::$container->get('test.enqueue.events.async_processor'); $message = new NullMessage(); $message->setProperty('event_name', 'anEventName'); @@ -62,7 +62,7 @@ public function testShouldRejectIfMessageDoesNotContainTransformerNameProperty() public function testShouldCallRealListener() { /** @var AsyncProcessor $processor */ - $processor = static::$container->get('enqueue.events.async_processor'); + $processor = static::$container->get('test.enqueue.events.async_processor'); $message = new NullMessage(); $message->setProperty('event_name', 'test_async'); @@ -93,7 +93,7 @@ public function testShouldCallRealListener() public function testShouldCallRealSubscriber() { /** @var AsyncProcessor $processor */ - $processor = static::$container->get('enqueue.events.async_processor'); + $processor = static::$container->get('test.enqueue.events.async_processor'); $message = new NullMessage(); $message->setProperty('event_name', 'test_async_subscriber'); diff --git a/pkg/enqueue-bundle/Tests/Functional/RoutesCommandTest.php b/pkg/enqueue-bundle/Tests/Functional/RoutesCommandTest.php index afefe6482..4970e9b43 100644 --- a/pkg/enqueue-bundle/Tests/Functional/RoutesCommandTest.php +++ b/pkg/enqueue-bundle/Tests/Functional/RoutesCommandTest.php @@ -25,12 +25,12 @@ public function testShouldDisplayRegisteredTopics() $tester = new CommandTester($command); $tester->execute([]); - $expected = <<<'OUTPUT' -| topic | theTopic | default (prefixed) | test_topic_subscriber_processor | (hidden) | -OUTPUT; - $this->assertSame(0, $tester->getStatusCode()); - $this->assertContains($expected, $tester->getDisplay()); + $this->assertContains('| topic', $tester->getDisplay()); + $this->assertContains('| theTopic', $tester->getDisplay()); + $this->assertContains('| default (prefixed)', $tester->getDisplay()); + $this->assertContains('| test_topic_subscriber_processor', $tester->getDisplay()); + $this->assertContains('| (hidden)', $tester->getDisplay()); } public function testShouldDisplayCommands() @@ -41,11 +41,11 @@ public function testShouldDisplayCommands() $tester = new CommandTester($command); $tester->execute([]); - $expected = <<<'OUTPUT' -| command | theCommand | default (prefixed) | test_command_subscriber_processor | (hidden) | -OUTPUT; - $this->assertSame(0, $tester->getStatusCode()); - $this->assertContains($expected, $tester->getDisplay()); + $this->assertContains('| command', $tester->getDisplay()); + $this->assertContains('| theCommand', $tester->getDisplay()); + $this->assertContains('| test_command_subscriber_processor', $tester->getDisplay()); + $this->assertContains('| default (prefixed)', $tester->getDisplay()); + $this->assertContains('| (hidden)', $tester->getDisplay()); } }