diff --git a/src/Commands/CreateQueueCommand.php b/src/Commands/CreateQueueCommand.php index c2b4768..cbacc4e 100644 --- a/src/Commands/CreateQueueCommand.php +++ b/src/Commands/CreateQueueCommand.php @@ -24,8 +24,12 @@ public function action( ): int { $location = CloudTasksClient::locationName($config['project_id'], $config['location']); $cloudQueue = new Queue(); - $cloudQueue->setName(CloudTasksClient::queueName( - $config['project_id'], $config['location'], $queueName ?? $config['queue']) + $cloudQueue->setName( + CloudTasksClient::queueName( + $config['project_id'], + $config['location'], + $queueName ?? $config['queue'] + ) ); $cloudQueue = $queueModifier->apply($cloudQueue, $config['settings'] ?? []); $client->createQueue($location, $cloudQueue); diff --git a/src/Commands/DeleteQueueCommand.php b/src/Commands/DeleteQueueCommand.php index c9f7638..51feac4 100644 --- a/src/Commands/DeleteQueueCommand.php +++ b/src/Commands/DeleteQueueCommand.php @@ -29,7 +29,9 @@ public function action(CloudTasksClient $client, array $config, string $namespac return 0; } $queueName = CloudTasksClient::queueName( - $config['project_id'], $config['location'], $queueName ?? $config['queue'] + $config['project_id'], + $config['location'], + $queueName ?? $config['queue'] ); $client->deleteQueue($queueName); $this->line("Queue {$namespaceName} has been deleted."); diff --git a/src/Commands/ListTasksCommand.php b/src/Commands/ListTasksCommand.php index 4d3a9f7..79a7ccb 100644 --- a/src/Commands/ListTasksCommand.php +++ b/src/Commands/ListTasksCommand.php @@ -22,7 +22,9 @@ public function action( array $config, ): int { $cloudQueueName = CloudTasksClient::queueName( - $config['project_id'], $config['location'], $queueName ?? $config['queue'] + $config['project_id'], + $config['location'], + $queueName ?? $config['queue'] ); $pagedResponse = $client->listTasks($cloudQueueName); diff --git a/src/Commands/PurgeQueueCommand.php b/src/Commands/PurgeQueueCommand.php index 394229b..33086db 100644 --- a/src/Commands/PurgeQueueCommand.php +++ b/src/Commands/PurgeQueueCommand.php @@ -22,7 +22,9 @@ public function action(CloudTasksClient $client, string $namespaceName, string|n return 0; } $cloudQueueName = CloudTasksClient::queueName( - $config['project_id'], $config['location'], $queueName ?? $config['queue'] + $config['project_id'], + $config['location'], + $queueName ?? $config['queue'] ); $client->purgeQueue($cloudQueueName); $this->line("Queue {$namespaceName} is being purged."); diff --git a/src/Commands/QueueStatsCommand.php b/src/Commands/QueueStatsCommand.php index 5d02bc6..e1f6cab 100644 --- a/src/Commands/QueueStatsCommand.php +++ b/src/Commands/QueueStatsCommand.php @@ -19,10 +19,12 @@ class QueueStatsCommand extends QueueInteractionCommand public function action(CloudTasksClient $client, string $namespaceName, string|null $queueName, array $config): int { $cloudQueueName = CloudTasksClient::queueName( - $config['project_id'], $config['location'], $queueName ?? $config['queue'] + $config['project_id'], + $config['location'], + $queueName ?? $config['queue'] ); $cloudQueue = $client->getQueue($cloudQueueName, [ - 'readMask' => new FieldMask(['paths' => ['state', 'stats']]) + 'readMask' => new FieldMask(['paths' => ['state', 'stats']]), ]); $stats = $cloudQueue->getStats(); diff --git a/src/Commands/QueueStatusCommand.php b/src/Commands/QueueStatusCommand.php index ea76f49..287962c 100644 --- a/src/Commands/QueueStatusCommand.php +++ b/src/Commands/QueueStatusCommand.php @@ -25,7 +25,9 @@ public function action(CloudTasksClient $client, string $namespaceName, string|n { $shouldToggle = (bool) $this->option('toggle'); $cloudQueueName = CloudTasksClient::queueName( - $config['project_id'], $config['location'], $queueName ?? $config['queue'] + $config['project_id'], + $config['location'], + $queueName ?? $config['queue'] ); $cloudQueue = $client->getQueue($cloudQueueName); $this->line(sprintf( diff --git a/src/Commands/UpdateQueueCommand.php b/src/Commands/UpdateQueueCommand.php index bb157ee..5b9b006 100644 --- a/src/Commands/UpdateQueueCommand.php +++ b/src/Commands/UpdateQueueCommand.php @@ -23,7 +23,9 @@ public function action( CloudQueueModifier $queueModifier ): int { $cloudQueueName = CloudTasksClient::queueName( - $config['project_id'], $config['location'], $queueName ?? $config['queue'] + $config['project_id'], + $config['location'], + $queueName ?? $config['queue'] ); $cloudQueue = new Queue(); $cloudQueue->setName($cloudQueueName); diff --git a/src/Dispatchers/AppEngineDispatcher.php b/src/Dispatchers/AppEngineDispatcher.php index b5b5a59..c7d2916 100644 --- a/src/Dispatchers/AppEngineDispatcher.php +++ b/src/Dispatchers/AppEngineDispatcher.php @@ -67,8 +67,9 @@ public function size($queue = null): int { $queueName = Client::queueName($this->projectId, $this->location, $queue); $cloudQueue = $this->client->getQueue($queueName, [ - 'readMask' => new FieldMask(['paths' => ['stats.tasksCount']]) + 'readMask' => new FieldMask(['paths' => ['stats.tasksCount']]), ]); + return (int) $cloudQueue->getStats()->getTasksCount(); } } diff --git a/src/Dispatchers/HttpDispatcher.php b/src/Dispatchers/HttpDispatcher.php index 67a800c..83d5e06 100644 --- a/src/Dispatchers/HttpDispatcher.php +++ b/src/Dispatchers/HttpDispatcher.php @@ -68,8 +68,9 @@ public function size($queue = null): int { $queueName = Client::queueName($this->projectId, $this->location, $queue); $cloudQueue = $this->client->getQueue($queueName, [ - 'readMask' => new FieldMask(['paths' => ['stats.tasksCount']]) + 'readMask' => new FieldMask(['paths' => ['stats.tasksCount']]), ]); + return (int) $cloudQueue->getStats()->getTasksCount(); } } diff --git a/src/Exceptions/CloudTasksQueueDoesNotExistException.php b/src/Exceptions/CloudTasksQueueDoesNotExistException.php index 806c398..5e437c6 100644 --- a/src/Exceptions/CloudTasksQueueDoesNotExistException.php +++ b/src/Exceptions/CloudTasksQueueDoesNotExistException.php @@ -15,8 +15,7 @@ public function __construct(protected string $connection, protected string $queu public function getSolution(): Solution { - return new class($this->connection, $this->queue) implements Solution { - + return new class ($this->connection, $this->queue) implements Solution { public function __construct(protected string $connection, protected string $queue) { } @@ -39,7 +38,7 @@ public function getSolutionDescription(): string public function getDocumentationLinks(): array { return [ - 'Google Cloud - Cloud Tasks - Creating Queues' => 'https://cloud.google.com/tasks/docs/creating-queues' + 'Google Cloud - Cloud Tasks - Creating Queues' => 'https://cloud.google.com/tasks/docs/creating-queues', ]; } }; diff --git a/src/Exceptions/ServiceEmailNotSetException.php b/src/Exceptions/ServiceEmailNotSetException.php index b6be9d4..3078d9d 100644 --- a/src/Exceptions/ServiceEmailNotSetException.php +++ b/src/Exceptions/ServiceEmailNotSetException.php @@ -15,8 +15,7 @@ public function __construct(protected string $connection, protected string $queu public function getSolution(): Solution { - return new class($this->connection) implements Solution { - + return new class ($this->connection) implements Solution { public function __construct(protected string $connection) { } diff --git a/tests/CommandsTest.php b/tests/CommandsTest.php index 46d41c7..a01e6f8 100644 --- a/tests/CommandsTest.php +++ b/tests/CommandsTest.php @@ -2,7 +2,6 @@ namespace TradeCoverExchange\GoogleCloudTaskLaravel\Tests; -use Google\ApiCore\Page; use Google\ApiCore\PagedListResponse; use Google\Cloud\Tasks\V2beta3\Attempt; use Google\Cloud\Tasks\V2beta3\CloudTasksClient; @@ -10,7 +9,6 @@ use Google\Cloud\Tasks\V2beta3\Queue\State; use Google\Cloud\Tasks\V2beta3\QueueStats; use Google\Cloud\Tasks\V2beta3\Task; -use Google\Protobuf\FieldMask; use Google\Protobuf\Timestamp; use Illuminate\Support\Carbon; use Mockery\MockInterface; @@ -32,7 +30,6 @@ public function setUp(): void ->withAnyArgs() ->once() ->andReturn($this->client); - }); } @@ -51,7 +48,7 @@ public function testCreatingQueue() ->once(); $this->artisan('google:cloud:queue:create', [ - 'name' => 'http_cloud_tasks' + 'name' => 'http_cloud_tasks', ]) ->assertExitCode(0); } @@ -63,7 +60,7 @@ public function testDeletingQueue() ->once(); $this->artisan('google:cloud:queue:delete', [ - 'name' => 'http_cloud_tasks' + 'name' => 'http_cloud_tasks', ]) ->expectsQuestion('This action will delete all unfinished tasks permanently, do you wish to continue?', 'y') ->assertExitCode(0); @@ -89,7 +86,7 @@ public function testPurgingQueue() ->once(); $this->artisan('google:cloud:queue:clear', [ - 'name' => 'http_cloud_tasks' + 'name' => 'http_cloud_tasks', ]) ->expectsQuestion('This action will delete all unfinished tasks permanently, do you wish to continue?', 'y') ->assertExitCode(0); @@ -117,7 +114,7 @@ public function testUpdateQueue() ->once(); $this->artisan('google:cloud:queue:update', [ - 'name' => 'http_cloud_tasks' + 'name' => 'http_cloud_tasks', ]) ->assertExitCode(0); } @@ -131,7 +128,7 @@ public function testProvidingStats() $this->client ->shouldReceive('getQueue') - ->with('projects/test/locations/europe-west1/queues/default', \Mockery::on(fn($value) => is_array($value))) + ->with('projects/test/locations/europe-west1/queues/default', \Mockery::on(fn ($value) => is_array($value))) ->andReturn($cloudQueue); $cloudQueue->setState(Queue\State::RUNNING); @@ -142,7 +139,7 @@ public function testProvidingStats() $stats->setOldestEstimatedArrivalTime((new Timestamp())->setSeconds(now()->timestamp)); $this->artisan('google:cloud:queue:stats', [ - 'name' => 'http_cloud_tasks' + 'name' => 'http_cloud_tasks', ]) ->expectsTable([ 'queue', @@ -180,7 +177,7 @@ public function testProvidesTheQueueStatus() $cloudQueue->setState(Queue\State::RUNNING); $this->artisan('google:cloud:queue:status', [ - 'name' => 'http_cloud_tasks' + 'name' => 'http_cloud_tasks', ]) ->expectsOutput('Queue http_cloud_tasks:default is running') ->assertExitCode(0); @@ -249,7 +246,9 @@ public function testRetrievesListOfTasks() $paginated = \Mockery::mock(PagedListResponse::class) ->shouldReceive('iterateAllElements') ->andReturn(function () use ($tasks): \Generator { - foreach ($tasks as $task) yield $task; + foreach ($tasks as $task) { + yield $task; + } }) ->getMock(); diff --git a/tests/MonitorCommandTest.php b/tests/MonitorCommandTest.php index e711ce9..3df4953 100644 --- a/tests/MonitorCommandTest.php +++ b/tests/MonitorCommandTest.php @@ -5,8 +5,6 @@ use Google\Cloud\Tasks\V2beta3\CloudTasksClient; use Google\Cloud\Tasks\V2beta3\Queue; use Google\Cloud\Tasks\V2beta3\QueueStats; -use Google\Protobuf\FieldMask; -use Illuminate\Queue\Console\MonitorCommand; use Mockery\MockInterface; use Orchestra\Testbench\TestCase; use TradeCoverExchange\GoogleCloudTaskLaravel\CloudTaskServiceProvider; @@ -26,7 +24,6 @@ public function setUp(): void ->withAnyArgs() ->once() ->andReturn($this->client); - }); } @@ -37,17 +34,17 @@ public function testQueueWorksWithMonitorCommand() $this->client ->shouldReceive('getQueue') - ->with('projects/test/locations/europe-west1/queues/default', \Mockery::on(fn($value) => is_array($value))) + ->with('projects/test/locations/europe-west1/queues/default', \Mockery::on(fn ($value) => is_array($value))) ->andReturn($cloudQueue); $cloudQueue->setStats($stats); $stats->setTasksCount(10); $this->artisan('queue:monitor', [ - 'queues' => 'http_cloud_tasks:default' + 'queues' => 'http_cloud_tasks:default', ]) ->expectsTable(['Connection', 'Queue', 'Size', 'Status'], [[ - 'http_cloud_tasks', 'default', '10', 'OK' + 'http_cloud_tasks', 'default', '10', 'OK', ]]) ->assertExitCode(0); }