aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-09-13 20:31:32 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-09-13 20:32:52 +0200
commite01a3c98d6908e95121b5ade0161f40af1b05ca6 (patch)
treee8cba50cc7cbf07720ddae7647d5c07e3e245f04 /src
parent5d002e9bdfd814e77e5842fe6c18d14f74493726 (diff)
downloadwallabag-e01a3c98d6908e95121b5ade0161f40af1b05ca6.tar.gz
wallabag-e01a3c98d6908e95121b5ade0161f40af1b05ca6.tar.zst
wallabag-e01a3c98d6908e95121b5ade0161f40af1b05ca6.zip
Display how many messages are queue
- update the docker-composer to add Redis - add migrations
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig2
-rw-r--r--src/Wallabag/ImportBundle/Controller/ImportController.php54
-rw-r--r--src/Wallabag/ImportBundle/Resources/views/Import/check_queue.html.twig11
3 files changed, 67 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
index b70198da..23938b21 100644
--- a/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
+++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/layout.html.twig
@@ -19,6 +19,8 @@
19 Materialize.toast('{{ flashMessage|trans }}', 4000); 19 Materialize.toast('{{ flashMessage|trans }}', 4000);
20 </script> 20 </script>
21 {% endfor %} 21 {% endfor %}
22
23 {{ render(controller("WallabagImportBundle:Import:checkQueue")) }}
22{% endblock %} 24{% endblock %}
23 25
24{% block menu %} 26{% block menu %}
diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php
index c1486e38..d670746c 100644
--- a/src/Wallabag/ImportBundle/Controller/ImportController.php
+++ b/src/Wallabag/ImportBundle/Controller/ImportController.php
@@ -16,4 +16,58 @@ class ImportController extends Controller
16 'imports' => $this->get('wallabag_import.chain')->getAll(), 16 'imports' => $this->get('wallabag_import.chain')->getAll(),
17 ]); 17 ]);
18 } 18 }
19
20 /**
21 * Display how many messages are queue (both in Redis and RabbitMQ).
22 */
23 public function checkQueueAction()
24 {
25 $nbRedisMessages = null;
26 $nbRabbitMessages = null;
27
28 if ($this->get('craue_config')->get('import_with_rabbitmq')) {
29 $nbRabbitMessages = $this->getTotalMessageInRabbitQueue('pocket')
30 + $this->getTotalMessageInRabbitQueue('readability')
31 + $this->getTotalMessageInRabbitQueue('wallabag_v1')
32 + $this->getTotalMessageInRabbitQueue('wallabag_v2')
33 ;
34 } elseif ($this->get('craue_config')->get('import_with_redis')) {
35 $redis = $this->get('wallabag_core.redis.client');
36
37 $nbRedisMessages = $redis->llen('wallabag.import.pocket')
38 + $redis->llen('wallabag.import.readability')
39 + $redis->llen('wallabag.import.wallabag_v1')
40 + $redis->llen('wallabag.import.wallabag_v2')
41 ;
42 }
43
44 return $this->render('WallabagImportBundle:Import:check_queue.html.twig', [
45 'nbRedisMessages' => $nbRedisMessages,
46 'nbRabbitMessages' => $nbRabbitMessages,
47 ]);
48 }
49
50 /**
51 * Count message in RabbitMQ queue.
52 * It get one message without acking it (so it'll stay in the queue)
53 * which will include the total of *other* messages in the queue.
54 * Adding one to that messages will result in the full total message.
55 *
56 * @param string $importService The import service related: pocket, readability, wallabag_v1 or wallabag_v2
57 *
58 * @return int
59 */
60 private function getTotalMessageInRabbitQueue($importService)
61 {
62 $message = $this
63 ->get('old_sound_rabbit_mq.import_'.$importService.'_consumer')
64 ->getChannel()
65 ->basic_get('wallabag.import.'.$importService);
66
67 if (null === $message) {
68 return 0;
69 }
70
71 return $message->delivery_info['message_count'] + 1;
72 }
19} 73}
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
index 00000000..7168ea35
--- /dev/null
+++ b/src/Wallabag/ImportBundle/Resources/views/Import/check_queue.html.twig
@@ -0,0 +1,11 @@
1{% if nbRedisMessages > 0 %}
2 <script>
3 Materialize.toast('Messages in queue: {{ nbRedisMessages }}', 4000);
4 </script>
5{% endif %}
6
7{% if nbRabbitMessages > 0 %}
8 <script>
9 Materialize.toast('Messages in queue: {{ nbRabbitMessages }}', 4000);
10 </script>
11{% endif %}