Skip to content

Commit

Permalink
Updates style of roadrunner jobs list command. (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
butschster committed Mar 28, 2023
1 parent 126be0c commit ea273fb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
64 changes: 49 additions & 15 deletions src/Console/Command/Queue/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
use Spiral\Console\Command;
use Spiral\RoadRunner\Jobs\JobsInterface;
use Spiral\RoadRunner\Jobs\Queue;
use Spiral\RoadRunner\Jobs\QueueInterface;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Helper\TableCell;
use Symfony\Component\Console\Helper\TableCellStyle;

final class ListCommand extends Command
{
Expand All @@ -24,26 +27,57 @@ public function perform(JobsInterface $jobs): int
return self::SUCCESS;
}

$queues = \array_map(static function (QueueInterface $queue): array {
\assert($queue instanceof Queue);
$stat = $queue->getPipelineStat();

$fontColor = $stat->getReady() ? 'green' : 'gray';
$defaultColor = $stat->getReady() ? 'default' : 'gray';
$activeFont = $stat->getReady() ? 'bold' : '';

return [
'name' => new TableCell($stat->getPipeline(), [
'style' => new TableCellStyle(['fg' => $fontColor, 'options' => $activeFont]),
]),
'driver' => new TableCell($stat->getDriver(), [
'style' => new TableCellStyle(
['fg' => $defaultColor, 'options' => $activeFont]
),
]),
'priority' => new TableCell((string)$stat->getPriority(), [
'style' => new TableCellStyle(
['fg' => $defaultColor, 'options' => $activeFont]
),
]),
'active_jobs' => new TableCell((string)$stat->getActive(), [
'style' => new TableCellStyle(
['fg' => $stat->getActive() > 0 ? 'green' : $defaultColor, 'options' => $activeFont]
),
]),
'delayed_jobs' => new TableCell((string)$stat->getDelayed(), [
'style' => new TableCellStyle(
['fg' => $stat->getDelayed() > 0 ? 'green' : $defaultColor, 'options' => $activeFont]
),
]),
'reserved_jobs' => new TableCell((string)$stat->getReserved(), [
'style' => new TableCellStyle(
['fg' => $stat->getReserved() > 0 ? 'green' : $defaultColor, 'options' => $activeFont]
),
]),
'is_active' => $stat->getReady() ? '<fg=green> ✓ </>' : '<fg=red> ✖ </>',
];
}, $queues);

\ksort($queues);

$table = new Table($this->output);

$table->setHeaders(
['Name', 'Driver', 'Priority', 'Active jobs', 'Delayed jobs', 'Reserved jobs', 'Is active'],
['Name', 'Driver', 'Priority', 'Active jobs', 'Delayed jobs', 'Reserved jobs', 'Is active',],
);

foreach ($queues as $queue) {
/** @var Queue $queue */

$stat = $queue->getPipelineStat();

$table->addRow([
$stat->getPipeline(),
$stat->getDriver(),
$stat->getPriority(),
$stat->getActive(),
$stat->getDelayed(),
$stat->getReserved(),
$stat->getReady() ? '<fg=green> ✓ </>' : '<fg=red> ✖ </>',
]);
foreach ($queues as $data) {
$table->addRow($data);
}

$table->render();
Expand Down
8 changes: 4 additions & 4 deletions tests/src/Console/Command/Queue/ListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ public function testGetsListOfAvailablePipelines()
$jobs = \Mockery::mock(JobsInterface::class);
$this->getContainer()->bind(JobsInterface::class, $jobs);

$jobs->shouldReceive('getIterator')->once()->andReturn(
$jobs->shouldReceive('getIterator')->andReturn(
new \ArrayIterator([
'memory' => $memory = \Mockery::mock(QueueInterface::class),
'memory' => $queue = \Mockery::mock(QueueInterface::class),
'amqp' => $amqp = \Mockery::mock(QueueInterface::class),
])
);

$memory->shouldReceive('getPipelineStat')->once()->andReturn(
$queue->shouldReceive('getPipelineStat')->once()->andReturn(
new Stat([
'pipeline' => 'test',
'driver' => 'memory',
Expand Down Expand Up @@ -54,8 +54,8 @@ public function testGetsListOfAvailablePipelines()
+---------+--------+----------+-------------+--------------+---------------+-----------+
| Name | Driver | Priority | Active jobs | Delayed jobs | Reserved jobs | Is active |
+---------+--------+----------+-------------+--------------+---------------+-----------+
| test | memory | 200 | 100 | 55 | 8 | ✓ |
| default | amqp | 250 | 110 | 88 | 56 | ✖ |
| test | memory | 200 | 100 | 55 | 8 | ✓ |
+---------+--------+----------+-------------+--------------+---------------+-----------+
EOL,
$this->runCommand('rr:jobs:list')
Expand Down

0 comments on commit ea273fb

Please sign in to comment.