diff --git a/CHANGELOG.md b/CHANGELOG.md index c5feec75f..aa91288d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Change Log +## [0.8.8](https://github.com/php-enqueue/enqueue-dev/tree/0.8.8) (2017-11-13) +[Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.8.7...0.8.8) + +- \[Redis\] add dsn support for symfony bundle. [\#266](https://github.com/php-enqueue/enqueue-dev/pull/266) ([wilson-ng](https://github.com/wilson-ng)) + +- onIdle is not triggered [\#260](https://github.com/php-enqueue/enqueue-dev/issues/260) +- On exception Context is not set [\#259](https://github.com/php-enqueue/enqueue-dev/issues/259) +- \[consumption\]\[amqp\] onIdle is never called. [\#265](https://github.com/php-enqueue/enqueue-dev/pull/265) ([makasim](https://github.com/makasim)) +- \[consumption\] fix context is missing message on exception. [\#264](https://github.com/php-enqueue/enqueue-dev/pull/264) ([makasim](https://github.com/makasim)) + ## [0.8.7](https://github.com/php-enqueue/enqueue-dev/tree/0.8.7) (2017-11-10) [Full Changelog](https://github.com/php-enqueue/enqueue-dev/compare/0.8.6...0.8.7) diff --git a/pkg/enqueue/Consumption/QueueConsumer.php b/pkg/enqueue/Consumption/QueueConsumer.php index 4e59abcd8..bea21e561 100644 --- a/pkg/enqueue/Consumption/QueueConsumer.php +++ b/pkg/enqueue/Consumption/QueueConsumer.php @@ -171,7 +171,7 @@ public function consume(ExtensionInterface $runtimeExtension = null) while (true) { try { if ($this->psrContext instanceof AmqpContext) { - $callback = function (AmqpMessage $message, AmqpConsumer $consumer) use ($extension, $logger) { + $callback = function (AmqpMessage $message, AmqpConsumer $consumer) use ($extension, $logger, &$context) { $currentProcessor = null; /** @var PsrQueue $queue */ @@ -204,6 +204,9 @@ public function consume(ExtensionInterface $runtimeExtension = null) } $this->psrContext->consume($this->receiveTimeout); + + usleep($this->idleTimeout * 1000); + $extension->onIdle($context); } else { /** @var PsrQueue $queue */ foreach ($this->boundProcessors as list($queue, $processor)) { diff --git a/pkg/redis/RedisMessage.php b/pkg/redis/RedisMessage.php index ca44579d6..754de075f 100644 --- a/pkg/redis/RedisMessage.php +++ b/pkg/redis/RedisMessage.php @@ -175,7 +175,7 @@ public function getTimestamp() { $value = $this->getHeader('timestamp'); - return $value === null ? null : (int) $value; + return null === $value ? null : (int) $value; } /** diff --git a/pkg/redis/Symfony/RedisTransportFactory.php b/pkg/redis/Symfony/RedisTransportFactory.php index f24df84e4..df4f462d9 100644 --- a/pkg/redis/Symfony/RedisTransportFactory.php +++ b/pkg/redis/Symfony/RedisTransportFactory.php @@ -33,16 +33,23 @@ public function __construct($name = 'redis') public function addConfiguration(ArrayNodeDefinition $builder) { $builder + ->beforeNormalization() + ->ifTrue(function ($node) { + return empty($node['dsn']) && (empty($node['host']) || empty($node['vendor'])); + }) + ->thenInvalid('Invalid configuration %s') + ->end() ->children() + ->scalarNode('dsn') + ->info('The redis connection given as DSN. For example redis://host:port?vendor=predis') + ->end() ->scalarNode('host') - ->isRequired() ->cannotBeEmpty() ->info('can be a host, or the path to a unix domain socket') ->end() ->integerNode('port')->end() ->enumNode('vendor') ->values(['phpredis', 'predis']) - ->isRequired() ->cannotBeEmpty() ->info('The library used internally to interact with Redis server') ->end() @@ -67,7 +74,7 @@ public function addConfiguration(ArrayNodeDefinition $builder) public function createConnectionFactory(ContainerBuilder $container, array $config) { $factory = new Definition(RedisConnectionFactory::class); - $factory->setArguments([$config]); + $factory->setArguments([isset($config['dsn']) ? $config['dsn'] : $config]); $factoryId = sprintf('enqueue.transport.%s.connection_factory', $this->getName()); $container->setDefinition($factoryId, $factory); diff --git a/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php b/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php index 51c185b9b..06309824f 100644 --- a/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php +++ b/pkg/redis/Tests/RedisConnectionFactoryConfigTest.php @@ -106,7 +106,7 @@ public static function provideConfigs() ]; yield [ - 'redis://localhost:1234?foo=bar&lazy=0&persisted=true', + 'redis://localhost:1234?foo=bar&lazy=0&persisted=true&database=5', [ 'host' => 'localhost', 'port' => 1234, @@ -117,7 +117,7 @@ public static function provideConfigs() 'persisted' => true, 'lazy' => false, 'foo' => 'bar', - 'database' => 0, + 'database' => 5, ], ]; diff --git a/pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php b/pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php index ca7d402c8..3a1512d84 100644 --- a/pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php +++ b/pkg/redis/Tests/Symfony/RedisTransportFactoryTest.php @@ -62,6 +62,26 @@ public function testShouldAllowAddConfiguration() ], $config); } + public function testShouldAllowAddConfigurationFromDSN() + { + $transport = new RedisTransportFactory(); + $tb = new TreeBuilder(); + $rootNode = $tb->root('foo'); + + $transport->addConfiguration($rootNode); + $processor = new Processor(); + $config = $processor->process($tb->buildTree(), [[ + 'dsn' => 'redis://localhost:8080?vendor=predis&persisted=false&lazy=true&database=5', + ]]); + + $this->assertEquals([ + 'persisted' => false, + 'lazy' => true, + 'database' => 0, + 'dsn' => 'redis://localhost:8080?vendor=predis&persisted=false&lazy=true&database=5', + ], $config); + } + public function testShouldCreateConnectionFactory() { $container = new ContainerBuilder();