]> git.immae.eu Git - github/wallabag/wallabag.git/blob - src/Wallabag/ImportBundle/Controller/ImportController.php
Display how many messages are queue
[github/wallabag/wallabag.git] / src / Wallabag / ImportBundle / Controller / ImportController.php
1 <?php
2
3 namespace Wallabag\ImportBundle\Controller;
4
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6 use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
7
8 class ImportController extends Controller
9 {
10 /**
11 * @Route("/", name="import")
12 */
13 public function importAction()
14 {
15 return $this->render('WallabagImportBundle:Import:index.html.twig', [
16 'imports' => $this->get('wallabag_import.chain')->getAll(),
17 ]);
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 }
73 }