Skip to content

Fix async command\event pkgs #694

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Dec 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions pkg/async-command/DependencyInjection/AsyncCommandExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@

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,
])
->addTag('enqueue.transport.processor')
;
}
}
}
7 changes: 0 additions & 7 deletions pkg/async-command/Resources/config/services.yml

This file was deleted.

13 changes: 1 addition & 12 deletions pkg/async-command/RunCommandProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@

namespace Enqueue\AsyncCommand;

use Enqueue\Client\CommandSubscriberInterface;
use Enqueue\Consumption\Result;
use Interop\Queue\Context;
use Interop\Queue\Message;
use Interop\Queue\Processor;
use Symfony\Component\Process\PhpExecutableFinder;
use Symfony\Component\Process\Process;

final class RunCommandProcessor implements Processor, CommandSubscriberInterface
final class RunCommandProcessor implements Processor
{
/**
* @var string
Expand Down Expand Up @@ -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
*/
Expand Down
21 changes: 0 additions & 21 deletions pkg/async-command/Tests/RunCommandProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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);
}
}
8 changes: 1 addition & 7 deletions pkg/async-event-dispatcher/AsyncProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -51,9 +50,4 @@ public function process(Message $message, Context $context)

return self::ACK;
}

public static function getSubscribedCommand()
{
return Commands::DISPATCH_ASYNC_EVENTS;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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')
;
}
}
14 changes: 0 additions & 14 deletions pkg/async-event-dispatcher/Resources/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions pkg/enqueue-bundle/Tests/Functional/App/config/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ 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);
}

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();

Expand All @@ -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');
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down
20 changes: 10 additions & 10 deletions pkg/enqueue-bundle/Tests/Functional/RoutesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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());
}
}