From 1c479d6b97e29bf408efd7a0397525247596a9fd Mon Sep 17 00:00:00 2001 From: Yassine Guedidi Date: Sat, 30 Apr 2022 20:12:47 +0200 Subject: [PATCH] Autowire Redis and RabbitMQ services --- app/config/services_rabbit.yml | 69 ++++---------- app/config/services_redis.yml | 90 +++++-------------- .../Consumer/AbstractConsumer.php | 4 +- 3 files changed, 41 insertions(+), 122 deletions(-) diff --git a/app/config/services_rabbit.yml b/app/config/services_rabbit.yml index 0cd336ef3..e407745d2 100644 --- a/app/config/services_rabbit.yml +++ b/app/config/services_rabbit.yml @@ -8,80 +8,49 @@ services: wallabag_import.consumer.amqp.pocket: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\PocketImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\PocketImport' + wallabag_import.consumer.amqp.readability: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\ReadabilityImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\ReadabilityImport' + wallabag_import.consumer.amqp.instapaper: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\InstapaperImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\InstapaperImport' + wallabag_import.consumer.amqp.pinboard: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\PinboardImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\PinboardImport' + wallabag_import.consumer.amqp.delicious: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\DeliciousImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\DeliciousImport' + wallabag_import.consumer.amqp.wallabag_v1: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\WallabagV1Import' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\WallabagV1Import' + wallabag_import.consumer.amqp.wallabag_v2: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\WallabagV2Import' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\WallabagV2Import' + wallabag_import.consumer.amqp.elcurator: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\ElcuratorImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\ElcuratorImport' + wallabag_import.consumer.amqp.firefox: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\FirefoxImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\FirefoxImport' + wallabag_import.consumer.amqp.chrome: class: Wallabag\ImportBundle\Consumer\AMQPEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\ChromeImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\ChromeImport' diff --git a/app/config/services_redis.yml b/app/config/services_redis.yml index fc83f418c..02c7eba95 100644 --- a/app/config/services_redis.yml +++ b/app/config/services_redis.yml @@ -9,8 +9,7 @@ services: wallabag_import.queue.redis.readability: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.readability" + $queueName: "wallabag.import.readability" wallabag_import.producer.redis.readability: class: Wallabag\ImportBundle\Redis\Producer @@ -20,18 +19,13 @@ services: wallabag_import.consumer.redis.readability: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\ReadabilityImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\ReadabilityImport' # instapaper wallabag_import.queue.redis.instapaper: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.instapaper" + $queueName: "wallabag.import.instapaper" wallabag_import.producer.redis.instapaper: class: Wallabag\ImportBundle\Redis\Producer @@ -41,18 +35,13 @@ services: wallabag_import.consumer.redis.instapaper: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\InstapaperImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\InstapaperImport' # pinboard wallabag_import.queue.redis.pinboard: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.pinboard" + $queueName: "wallabag.import.pinboard" wallabag_import.producer.redis.pinboard: class: Wallabag\ImportBundle\Redis\Producer @@ -62,18 +51,13 @@ services: wallabag_import.consumer.redis.pinboard: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\PinboardImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\PinboardImport' # delicious wallabag_import.queue.redis.delicious: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.delicious" + $queueName: "wallabag.import.delicious" wallabag_import.producer.redis.delicious: class: Wallabag\ImportBundle\Redis\Producer @@ -83,18 +67,13 @@ services: wallabag_import.consumer.redis.delicious: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\DeliciousImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\DeliciousImport' # pocket wallabag_import.queue.redis.pocket: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.pocket" + $queueName: "wallabag.import.pocket" wallabag_import.producer.redis.pocket: class: Wallabag\ImportBundle\Redis\Producer @@ -104,18 +83,13 @@ services: wallabag_import.consumer.redis.pocket: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\PocketImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\PocketImport' # wallabag v1 wallabag_import.queue.redis.wallabag_v1: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.wallabag_v1" + $queueName: "wallabag.import.wallabag_v1" wallabag_import.producer.redis.wallabag_v1: class: Wallabag\ImportBundle\Redis\Producer @@ -125,18 +99,13 @@ services: wallabag_import.consumer.redis.wallabag_v1: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\WallabagV1Import' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\WallabagV1Import' # wallabag v2 wallabag_import.queue.redis.wallabag_v2: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.wallabag_v2" + $queueName: "wallabag.import.wallabag_v2" wallabag_import.producer.redis.wallabag_v2: class: Wallabag\ImportBundle\Redis\Producer @@ -146,18 +115,13 @@ services: wallabag_import.consumer.redis.wallabag_v2: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\WallabagV2Import' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\WallabagV2Import' # elcurator wallabag_import.queue.redis.elcurator: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.elcurator" + $queueName: "wallabag.import.elcurator" wallabag_import.producer.redis.elcurator: class: Wallabag\ImportBundle\Redis\Producer @@ -167,18 +131,13 @@ services: wallabag_import.consumer.redis.elcurator: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\ElcuratorImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\ElcuratorImport' # firefox wallabag_import.queue.redis.firefox: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.firefox" + $queueName: "wallabag.import.firefox" wallabag_import.producer.redis.firefox: class: Wallabag\ImportBundle\Redis\Producer @@ -188,18 +147,13 @@ services: wallabag_import.consumer.redis.firefox: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\FirefoxImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\FirefoxImport' # chrome wallabag_import.queue.redis.chrome: class: Simpleue\Queue\RedisQueue arguments: - - '@Predis\Client' - - "wallabag.import.chrome" + $queueName: "wallabag.import.chrome" wallabag_import.producer.redis.chrome: class: Wallabag\ImportBundle\Redis\Producer @@ -209,8 +163,4 @@ services: wallabag_import.consumer.redis.chrome: class: Wallabag\ImportBundle\Consumer\RedisEntryConsumer arguments: - - "@doctrine.orm.entity_manager" - - '@Wallabag\UserBundle\Repository\UserRepository' - - '@Wallabag\ImportBundle\Import\ChromeImport' - - "@event_dispatcher" - - "@logger" + $import: '@Wallabag\ImportBundle\Import\ChromeImport' diff --git a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php index e4bfbdf03..17c8561a6 100644 --- a/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php +++ b/src/Wallabag/ImportBundle/Consumer/AbstractConsumer.php @@ -2,7 +2,7 @@ namespace Wallabag\ImportBundle\Consumer; -use Doctrine\ORM\EntityManager; +use Doctrine\ORM\EntityManagerInterface; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -20,7 +20,7 @@ abstract class AbstractConsumer protected $eventDispatcher; protected $logger; - public function __construct(EntityManager $em, UserRepository $userRepository, AbstractImport $import, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger = null) + public function __construct(EntityManagerInterface $em, UserRepository $userRepository, AbstractImport $import, EventDispatcherInterface $eventDispatcher, LoggerInterface $logger = null) { $this->em = $em; $this->userRepository = $userRepository;