]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Display how many messages are queue
authorJeremy Benoist <jeremy.benoist@gmail.com>
Tue, 13 Sep 2016 18:31:32 +0000 (20:31 +0200)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Tue, 13 Sep 2016 18:32:52 +0000 (20:32 +0200)
- update the docker-composer to add Redis
- add migrations

app/DoctrineMigrations/Version20160911214952.php [new file with mode: 0644]
docker-compose.yml
src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
src/Wallabag/ImportBundle/Controller/ImportController.php
src/Wallabag/ImportBundle/Resources/views/Import/check_queue.html.twig [new file with mode: 0644]

diff --git a/app/DoctrineMigrations/Version20160911214952.php b/app/DoctrineMigrations/Version20160911214952.php
new file mode 100644 (file)
index 0000000..35809ce
--- /dev/null
@@ -0,0 +1,42 @@
+<?php
+
+namespace Application\Migrations;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+use Symfony\Component\DependencyInjection\ContainerAwareInterface;
+use Symfony\Component\DependencyInjection\ContainerInterface;
+
+class Version20160911214952 extends AbstractMigration implements ContainerAwareInterface
+{
+    /**
+     * @var ContainerInterface
+     */
+    private $container;
+
+    public function setContainer(ContainerInterface $container = null)
+    {
+        $this->container = $container;
+    }
+
+    private function getTable($tableName)
+    {
+        return $this->container->getParameter('database_table_prefix') . $tableName;
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        $this->addSql('INSERT INTO `'.$this->getTable('craue_config_setting').'` (`name`, `value`, `section`) VALUES (\'import_with_redis\', \'0\', \'import\')');
+        $this->addSql('INSERT INTO `'.$this->getTable('craue_config_setting').'` (`name`, `value`, `section`) VALUES (\'import_with_rabbitmq\', \'0\', \'import\')');
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+    }
+}
index a255b070490cbb088c092a17c0f996b2ea0d69bd..27f0f14fd852b2336db657f91bfc7498ee54d872 100644 (file)
@@ -11,6 +11,7 @@ services:
         links:
             - php:php
         command: nginx -c /nginx.conf
+
     php:
         build:
             context: docker/php
@@ -30,6 +31,7 @@ services:
             # If all DBMS are commented out, sqlite will be used as default
             # - ./docker/postgres/env
             # - ./docker/mariadb/env
+
     #postgres:
     #    image: postgres:9
     #    ports:
@@ -38,6 +40,7 @@ services:
     #        - ./docker/data/pgsql:/var/lib/postgresql/data
     #    env_file:
     #        - ./docker/postgres/env
+
     #mariadb:
     #    image: mariadb:10
     #    ports:
@@ -46,7 +49,13 @@ services:
     #        - ./docker/data/mariadb:/var/lib/mysql
     #    env_file:
     #        - ./docker/mariadb/env
+
     rabbitmq:
         image: rabbitmq:3-management
         ports:
             - "15672:15672"
+
+    rabbitmq:
+        image: redis
+        ports:
+            - "6379:6379"
index b70198da6bc68f3a9586e583c9fcbd14a2da19ce..23938b21ce7fd123a5b66526817af123dbb64528 100644 (file)
@@ -19,6 +19,8 @@
             Materialize.toast('{{ flashMessage|trans }}', 4000);
         </script>
     {% endfor %}
+
+    {{ render(controller("WallabagImportBundle:Import:checkQueue")) }}
 {% endblock %}
 
 {% block menu %}
index c1486e3821415307168c4ab1c091b0bd44ecfc98..d670746cb6b1792a89bf0d05827b7b5ad7257206 100644 (file)
@@ -16,4 +16,58 @@ class ImportController extends Controller
             'imports' => $this->get('wallabag_import.chain')->getAll(),
         ]);
     }
+
+    /**
+     * Display how many messages are queue (both in Redis and RabbitMQ).
+     */
+    public function checkQueueAction()
+    {
+        $nbRedisMessages = null;
+        $nbRabbitMessages = null;
+
+        if ($this->get('craue_config')->get('import_with_rabbitmq')) {
+            $nbRabbitMessages = $this->getTotalMessageInRabbitQueue('pocket')
+                + $this->getTotalMessageInRabbitQueue('readability')
+                + $this->getTotalMessageInRabbitQueue('wallabag_v1')
+                + $this->getTotalMessageInRabbitQueue('wallabag_v2')
+            ;
+        } elseif ($this->get('craue_config')->get('import_with_redis')) {
+            $redis = $this->get('wallabag_core.redis.client');
+
+            $nbRedisMessages = $redis->llen('wallabag.import.pocket')
+                + $redis->llen('wallabag.import.readability')
+                + $redis->llen('wallabag.import.wallabag_v1')
+                + $redis->llen('wallabag.import.wallabag_v2')
+            ;
+        }
+
+        return $this->render('WallabagImportBundle:Import:check_queue.html.twig', [
+            'nbRedisMessages' => $nbRedisMessages,
+            'nbRabbitMessages' => $nbRabbitMessages,
+        ]);
+    }
+
+    /**
+     * Count message in RabbitMQ queue.
+     * It get one message without acking it (so it'll stay in the queue)
+     * which will include the total of *other* messages in the queue.
+     * Adding one to that messages will result in the full total message.
+     *
+     * @param string $importService The import service related: pocket, readability, wallabag_v1 or wallabag_v2
+     *
+     * @return int
+     */
+    private function getTotalMessageInRabbitQueue($importService)
+    {
+        $message = $this
+            ->get('old_sound_rabbit_mq.import_'.$importService.'_consumer')
+            ->getChannel()
+            ->basic_get('wallabag.import.'.$importService);
+
+        if (null === $message) {
+            return 0;
+        }
+
+        return $message->delivery_info['message_count'] + 1;
+    }
 }
diff --git a/src/Wallabag/ImportBundle/Resources/views/Import/check_queue.html.twig b/src/Wallabag/ImportBundle/Resources/views/Import/check_queue.html.twig
new file mode 100644 (file)
index 0000000..7168ea3
--- /dev/null
@@ -0,0 +1,11 @@
+{% if nbRedisMessages > 0 %}
+    <script>
+        Materialize.toast('Messages in queue: {{ nbRedisMessages }}', 4000);
+    </script>
+{% endif %}
+
+{% if nbRabbitMessages > 0 %}
+    <script>
+        Materialize.toast('Messages in queue: {{ nbRabbitMessages }}', 4000);
+    </script>
+{% endif %}