mirror of https://github.com/wallabag/wallabag.git
Display how many messages are queue
- update the docker-composer to add Redis - add migrations
This commit is contained in:
parent
5d002e9bdf
commit
e01a3c98d6
|
@ -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)
|
||||
{
|
||||
}
|
||||
}
|
|
@ -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"
|
||||
|
|
|
@ -19,6 +19,8 @@
|
|||
Materialize.toast('{{ flashMessage|trans }}', 4000);
|
||||
</script>
|
||||
{% endfor %}
|
||||
|
||||
{{ render(controller("WallabagImportBundle:Import:checkQueue")) }}
|
||||
{% endblock %}
|
||||
|
||||
{% block menu %}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 %}
|
Loading…
Reference in New Issue