diff options
author | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
---|---|---|
committer | Paulino Michelazzo <paulino@michelazzo.com.br> | 2016-10-18 22:48:23 +0200 |
commit | 99731f0bb1f6fd2815eeb9af504ce86df927657b (patch) | |
tree | b080efc608d2bbd52b77a4a0067402007f50c5a8 /src/Wallabag/ImportBundle/Controller/ImportController.php | |
parent | 3a3c6b866b52721431bed22426d9abfcd0d2dfe0 (diff) | |
parent | 7180aaed45dce62e40620a9e4b202526ebd6a3bb (diff) | |
download | wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.gz wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.tar.zst wallabag-99731f0bb1f6fd2815eeb9af504ce86df927657b.zip |
Merge remote-tracking branch 'wallabag/master'
Diffstat (limited to 'src/Wallabag/ImportBundle/Controller/ImportController.php')
-rw-r--r-- | src/Wallabag/ImportBundle/Controller/ImportController.php | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php index c1486e38..15de75ff 100644 --- a/src/Wallabag/ImportBundle/Controller/ImportController.php +++ b/src/Wallabag/ImportBundle/Controller/ImportController.php | |||
@@ -16,4 +16,82 @@ 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 | * Only for admins. | ||
23 | */ | ||
24 | public function checkQueueAction() | ||
25 | { | ||
26 | $nbRedisMessages = null; | ||
27 | $nbRabbitMessages = null; | ||
28 | $redisNotInstalled = false; | ||
29 | $rabbitNotInstalled = false; | ||
30 | |||
31 | if (!$this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { | ||
32 | return $this->render('WallabagImportBundle:Import:check_queue.html.twig'); | ||
33 | } | ||
34 | |||
35 | if ($this->get('craue_config')->get('import_with_rabbitmq')) { | ||
36 | // in case rabbit is activated but not installed | ||
37 | try { | ||
38 | $nbRabbitMessages = $this->getTotalMessageInRabbitQueue('pocket') | ||
39 | + $this->getTotalMessageInRabbitQueue('readability') | ||
40 | + $this->getTotalMessageInRabbitQueue('wallabag_v1') | ||
41 | + $this->getTotalMessageInRabbitQueue('wallabag_v2') | ||
42 | + $this->getTotalMessageInRabbitQueue('firefox') | ||
43 | + $this->getTotalMessageInRabbitQueue('chrome') | ||
44 | + $this->getTotalMessageInRabbitQueue('instapaper') | ||
45 | ; | ||
46 | } catch (\Exception $e) { | ||
47 | $rabbitNotInstalled = true; | ||
48 | } | ||
49 | } elseif ($this->get('craue_config')->get('import_with_redis')) { | ||
50 | $redis = $this->get('wallabag_core.redis.client'); | ||
51 | |||
52 | try { | ||
53 | $nbRedisMessages = $redis->llen('wallabag.import.pocket') | ||
54 | + $redis->llen('wallabag.import.readability') | ||
55 | + $redis->llen('wallabag.import.wallabag_v1') | ||
56 | + $redis->llen('wallabag.import.wallabag_v2') | ||
57 | + $redis->llen('wallabag.import.firefox') | ||
58 | + $redis->llen('wallabag.import.chrome') | ||
59 | + $redis->llen('wallabag.import.instapaper') | ||
60 | ; | ||
61 | } catch (\Exception $e) { | ||
62 | $redisNotInstalled = true; | ||
63 | } | ||
64 | } | ||
65 | |||
66 | return $this->render('WallabagImportBundle:Import:check_queue.html.twig', [ | ||
67 | 'nbRedisMessages' => $nbRedisMessages, | ||
68 | 'nbRabbitMessages' => $nbRabbitMessages, | ||
69 | 'redisNotInstalled' => $redisNotInstalled, | ||
70 | 'rabbitNotInstalled' => $rabbitNotInstalled, | ||
71 | ]); | ||
72 | } | ||
73 | |||
74 | /** | ||
75 | * Count message in RabbitMQ queue. | ||
76 | * It get one message without acking it (so it'll stay in the queue) | ||
77 | * which will include the total of *other* messages in the queue. | ||
78 | * Adding one to that messages will result in the full total message. | ||
79 | * | ||
80 | * @param string $importService The import service related: pocket, readability, wallabag_v1 or wallabag_v2 | ||
81 | * | ||
82 | * @return int | ||
83 | */ | ||
84 | private function getTotalMessageInRabbitQueue($importService) | ||
85 | { | ||
86 | $message = $this | ||
87 | ->get('old_sound_rabbit_mq.import_'.$importService.'_consumer') | ||
88 | ->getChannel() | ||
89 | ->basic_get('wallabag.import.'.$importService); | ||
90 | |||
91 | if (null === $message) { | ||
92 | return 0; | ||
93 | } | ||
94 | |||
95 | return $message->delivery_info['message_count'] + 1; | ||
96 | } | ||
19 | } | 97 | } |