Skip to content

Commit

Permalink
Updates console commands for queue and cache component (#68)
Browse files Browse the repository at this point in the history
* Updates console commands for queue and cache component
- Deprecates commands with old names for queue
- Adds new commands with correct names for queue
- Deprecates command for cache components.

* Fixes unit tests

* Fixes unit tests
  • Loading branch information
butschster committed Mar 28, 2023
1 parent 00620ef commit 126be0c
Show file tree
Hide file tree
Showing 14 changed files with 113 additions and 15 deletions.
4 changes: 4 additions & 0 deletions src/Bootloader/CommandBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ private function configureJobs(ConsoleBootloader $console): void
$console->addCommand(Queue\PauseCommand::class);
$console->addCommand(Queue\ResumeCommand::class);
$console->addCommand(Queue\ListCommand::class);

$console->addCommand(Queue\DeprecatedPauseCommand::class);
$console->addCommand(Queue\DeprecatedResumeCommand::class);
$console->addCommand(Queue\DeprecatedListCommand::class);
}

private function configureCache(ConsoleBootloader $console): void
Expand Down
7 changes: 6 additions & 1 deletion src/Console/Command/Cache/ClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@
use Spiral\Cache\CacheStorageProviderInterface;
use Spiral\Console\Command;

/**
* @deprecated Will be removed in the next major release of RoadRunner Bridge (version 3.0)
*/
final class ClearCommand extends Command
{
protected const SIGNATURE = 'cache:clear {storage? : Storage name}';
protected const DESCRIPTION = 'Clear cache';
protected const DESCRIPTION = 'Clears the cache for the specified storage in the Spiral cache component.';

public function perform(CacheStorageProviderInterface $provider): int
{
$this->warning('WARNING: This command has been deprecated and will be removed in the next major release of RoadRunner Bridge (version 3.0).');

if ($this->isVerbose()) {
$this->writeln('<info>Cleaning application cache:</info>');
}
Expand Down
26 changes: 26 additions & 0 deletions src/Console/Command/Queue/DeprecatedListCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunnerBridge\Console\Command\Queue;

use Spiral\Console\Command;
use Spiral\Console\Console;

/**
* @deprecated Will be removed in the next major release of RoadRunner Bridge (version 3.0)
*/
final class DeprecatedListCommand extends Command
{
protected const SIGNATURE = 'roadrunner:list';
protected const DESCRIPTION = '(Deprecated) Displays a list of available job pipelines for the RoadRunner';

public function perform(Console $console): int
{
$this->warning(
'WARNING: This command has been deprecated and will be removed in the next major release of RoadRunner Bridge (version 3.0).',
);

return $console->run('rr:jobs:list', [], $this->output)->getCode();
}
}
28 changes: 28 additions & 0 deletions src/Console/Command/Queue/DeprecatedPauseCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunnerBridge\Console\Command\Queue;

use Spiral\Console\Command;
use Spiral\Console\Console;

/**
* @deprecated Will be removed in the next major release of RoadRunner Bridge (version 3.0)
*/
final class DeprecatedPauseCommand extends Command
{
protected const SIGNATURE = 'roadrunner:pause {pipeline : Pipeline name}';
protected const DESCRIPTION = '(Deprecated) Pauses the consumption of jobs for the specified pipeline in the RoadRunner.';

public function perform(Console $console): int
{
$this->warning(
'WARNING: This command has been deprecated and will be removed in the next major release of RoadRunner Bridge (version 3.0).',
);

return $console->run('rr:jobs:pause', [
'pipeline' => $this->argument('pipeline'),
], $this->output)->getCode();
}
}
28 changes: 28 additions & 0 deletions src/Console/Command/Queue/DeprecatedResumeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace Spiral\RoadRunnerBridge\Console\Command\Queue;

use Spiral\Console\Command;
use Spiral\Console\Console;

/**
* @deprecated Will be removed in the next major release of RoadRunner Bridge (version 3.0)
*/
final class DeprecatedResumeCommand extends Command
{
protected const SIGNATURE = 'roadrunner:resume {pipeline : Pipeline name}';
protected const DESCRIPTION = '(Deprecated) Resumes the consumption of jobs for the specified pipeline in the RoadRunner.';

public function perform(Console $console): int
{
$this->warning(
'WARNING: This command has been deprecated and will be removed in the next major release of RoadRunner Bridge (version 3.0).',
);

return $console->run('rr:jobs:pause', [
'pipeline' => $this->argument('pipeline'),
], $this->output)->getCode();
}
}
8 changes: 5 additions & 3 deletions src/Console/Command/Queue/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,23 @@

final class ListCommand extends Command
{
protected const SIGNATURE = 'roadrunner:list';
protected const DESCRIPTION = 'List available roadrunner pipelines';
protected const SIGNATURE = 'rr:jobs:list';
protected const DESCRIPTION = 'Displays a list of available job pipelines for the RoadRunner';

public function perform(JobsInterface $jobs): int
{
$queues = \iterator_to_array($jobs->getIterator());

if ($queues === []) {
$this->info('No job pipelines are currently declared for the RoadRunner.');

return self::SUCCESS;
}

$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) {
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Queue/PauseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

final class PauseCommand extends Command
{
protected const SIGNATURE = 'roadrunner:pause {pipeline : Pipeline name}';
protected const DESCRIPTION = 'Pause consuming jobs for pipeline with given name';
protected const SIGNATURE = 'rr:jobs:pause {pipeline : Pipeline name}';
protected const DESCRIPTION = 'Pauses the consumption of jobs for the specified pipeline in the RoadRunner.';

public function perform(JobsInterface $jobs): int
{
Expand Down
4 changes: 2 additions & 2 deletions src/Console/Command/Queue/ResumeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

final class ResumeCommand extends Command
{
protected const SIGNATURE = 'roadrunner:resume {pipeline : Pipeline name}';
protected const DESCRIPTION = 'Resume consuming jobs for pipeline with given name';
protected const SIGNATURE = 'rr:jobs:consume {pipeline : Pipeline name}';
protected const DESCRIPTION = 'Resumes the consumption of jobs for the specified pipeline in the RoadRunner.';

public function perform(JobsInterface $jobs): int
{
Expand Down
5 changes: 3 additions & 2 deletions tests/app/GRPC/Generator/Bootloader/ExpectedBootloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

class ServiceBootloader extends Bootloader
{
public function __construct(public ConfiguratorInterface $config)
{
public function __construct(
public ConfiguratorInterface $config,
) {
}

public function init(EnvironmentInterface $env): void
Expand Down
5 changes: 3 additions & 2 deletions tests/app/GRPC/Generator/ExpectedServiceClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@

class UsersServiceClient implements UsersServiceInterface
{
public function __construct(public InterceptableCore $core)
{
public function __construct(
public InterceptableCore $core,
) {
}

public function Auth(ContextInterface $ctx, DTO\AuthRequest $in): DTO\AuthResponse
Expand Down
3 changes: 3 additions & 0 deletions tests/src/Bootloader/CentrifugoBootloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public function testCentrifugoWorkerShouldBeSingleton(): void
CentrifugoWorkerInterface::class,
CentrifugoWorker::class
);

// TODO fix problem with rr worker
ob_end_flush();
}

public function testErrorHandlerShouldBeSingleton(): void
Expand Down
2 changes: 1 addition & 1 deletion tests/src/Console/Command/Queue/ListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testGetsListOfAvailablePipelines()
| default | amqp | 250 | 110 | 88 | 56 | ✖ |
+---------+--------+----------+-------------+--------------+---------------+-----------+
EOL,
$this->runCommand('roadrunner:list')
$this->runCommand('rr:jobs:list')
);
}
}
2 changes: 1 addition & 1 deletion tests/src/Console/Command/Queue/PauseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testPausePipeline()

$jobs->shouldReceive('pause')->once()->with('foo');

$result = $this->runCommand('roadrunner:pause', ['pipeline' => 'foo']);
$result = $this->runCommand('rr:jobs:pause', ['pipeline' => 'foo']);
$this->assertStringContainsString('Pipeline [foo] has been paused.', $result);
}
}
2 changes: 1 addition & 1 deletion tests/src/Console/Command/Queue/ResumeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function testPausePipeline()

$jobs->shouldReceive('resume')->once()->with('foo');

$result = $this->runCommand('roadrunner:resume', ['pipeline' => 'foo']);
$result = $this->runCommand('rr:jobs:consume', ['pipeline' => 'foo']);
$this->assertStringContainsString('Pipeline [foo] has been resumed.', $result);
}
}

0 comments on commit 126be0c

Please sign in to comment.