Skip to content

Commit 3051de9

Browse files
committed
Refactor and rename for consistency
1 parent 3795f5d commit 3051de9

9 files changed

+60
-64
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,16 @@ Also, the dashboard has not been tested with high throughput queues.
122122

123123
To make use of it, enable it through the `.env` file:
124124

125-
```
126-
CLOUD_TASKS_MONITOR_ENABLED=true
127-
CLOUD_TASKS_MONITOR_ENABLED=MySecretLoginPasswordPleaseChangeThis
125+
```dotenv
126+
STACKKIT_CLOUD_TASKS_DASHBOARD_ENABLED=true
127+
STACKKIT_CLOUD_TASKS_DASHBOARD_PASSWORD=MySecretLoginPasswordPleaseChangeThis
128128
```
129129

130-
Then publish its assets:
130+
Then publish its assets and migrations:
131131

132-
```
132+
```php
133133
php artisan vendor:publish --tag=cloud-tasks
134+
php artisan migrate
134135
```
135136
</details>
136137
<details>
@@ -140,15 +141,13 @@ Then publish its assets:
140141
Set the `GOOGLE_APPLICATION_CREDENTIALS` environment variable with a path to the credentials file.
141142

142143
More info: https://cloud.google.com/docs/authentication/production
143-
</details>
144-
<details>
145-
<summary>Service Account Roles</summary>
146144

147145
If you're not using your master service account (which has all abilities), you must add the following roles to make it works:
148146
1. App Engine Viewer
149147
2. Cloud Tasks Enqueuer
150148
3. Cloud Tasks Viewer
151-
4. Service Account User
149+
4. Cloud Tasks Task Deleter
150+
5. Service Account User
152151
</details>
153152
<details>
154153
<summary>Configuring the queue</summary>

config/cloud-tasks.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
declare(strict_types=1);
44

55
return [
6-
'monitor' => [
7-
'enabled' => env('CLOUD_TASKS_MONITOR_ENABLED', false),
8-
'password' => env('CLOUD_TASKS_MONITOR_PASSWORD', '$2a$12$q3pRT5jjjjPlTSaGhoy.gupULnK.5lQEiquK5RVaWbGw9nYRy7gwi') // MyPassword1!
6+
'dashboard' => [
7+
'enabled' => env('STACKKIT_CLOUD_TASKS_DASHBOARD_ENABLED', false),
8+
'password' => env('STACKKIT_CLOUD_TASKS_DASHBOARD_PASSWORD', 'MyPassword1!')
99
],
1010
];

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<file>./tests/ConfigTest.php</file>
1414
<file>./tests/TaskHandlerTest.php</file>
1515
<file>./tests/CloudTasksApiTest.php</file>
16-
<file>./tests/CloudTasksMonitoringTest.php</file>
16+
<file>./tests/CloudTasksDashboardTest.php</file>
1717
</testsuite>
1818
</testsuites>
1919
<php>

src/CloudTasks.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,22 @@ public static function check($request)
3232
}
3333

3434
/**
35-
* Determine if the monitor is enabled.
35+
* Determine if the dashboard is enabled.
3636
*
3737
* @return bool
3838
*/
39-
public static function monitorEnabled(): bool
39+
public static function dashboardEnabled(): bool
4040
{
41-
return config('cloud-tasks.monitor.enabled') === true;
41+
return config('cloud-tasks.dashboard.enabled') === true;
4242
}
4343

4444
/**
45-
* Determine if the monitor is disabled.
45+
* Determine if the dashboard is disabled.
4646
*
4747
* @return bool
4848
*/
49-
public static function monitorDisabled(): bool
49+
public static function dashboardDisabled(): bool
5050
{
51-
return self::monitorEnabled() === false;
51+
return self::dashboardEnabled() === false;
5252
}
5353
}

src/CloudTasksApiController.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77
use Illuminate\Support\Carbon;
88
use Illuminate\Support\Collection;
99
use Illuminate\Support\Facades\DB;
10-
use Illuminate\Support\Facades\Hash;
1110
use Stackkit\LaravelGoogleCloudTasksQueue\Entities\StatRow;
1211
use const STR_PAD_LEFT;
1312

1413
class CloudTasksApiController
1514
{
1615
public function login(): ?string
1716
{
18-
$password = config('cloud-tasks.monitor.password');
17+
$password = config('cloud-tasks.dashboard.password');
1918

2019
if (!is_string($password)) {
2120
return null;
2221
}
2322

24-
$validPassword = Hash::check(request('password'), $password);
23+
$validPassword = hash_equals($password, request('password'));
2524

2625
if (!$validPassword) {
2726
return null;
@@ -35,7 +34,7 @@ public function dashboard(): array
3534
$dbDriver = config('database.connections.' . config('database.default') . '.driver');
3635

3736
if (!in_array($dbDriver, ['mysql', 'pgsql'])) {
38-
throw new Exception('Unsupported database driver for Cloud Tasks monitoring.');
37+
throw new Exception('Unsupported database driver for Cloud Tasks dashboard.');
3938
}
4039

4140
$groupBy = [

src/CloudTasksServiceProvider.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function boot(QueueManager $queue, Router $router): void
2424
$this->registerAssets();
2525
$this->registerMigrations();
2626
$this->registerRoutes($router);
27-
$this->registerMonitoring();
27+
$this->registerDashboard();
2828
}
2929

3030
private function registerClient(): void
@@ -55,7 +55,7 @@ private function registerConfig(): void
5555

5656
private function registerViews(): void
5757
{
58-
if (CloudTasks::monitorDisabled()) {
58+
if (CloudTasks::dashboardDisabled()) {
5959
// Larastan needs this view registered to check the service provider correctly.
6060
// return;
6161
}
@@ -65,7 +65,7 @@ private function registerViews(): void
6565

6666
private function registerAssets(): void
6767
{
68-
if (CloudTasks::monitorDisabled()) {
68+
if (CloudTasks::dashboardDisabled()) {
6969
return;
7070
}
7171

@@ -76,7 +76,7 @@ private function registerAssets(): void
7676

7777
private function registerMigrations(): void
7878
{
79-
if (CloudTasks::monitorDisabled()) {
79+
if (CloudTasks::dashboardDisabled()) {
8080
return;
8181
}
8282

@@ -89,7 +89,7 @@ private function registerRoutes(Router $router): void
8989
{
9090
$router->post('handle-task', [TaskHandler::class, 'handle'])->name('cloud-tasks.handle-task');
9191

92-
if (config('cloud-tasks.monitor.enabled') === false) {
92+
if (CloudTasks::dashboardDisabled()) {
9393
return;
9494
}
9595

@@ -116,14 +116,14 @@ private function registerRoutes(Router $router): void
116116
});
117117
}
118118

119-
private function registerMonitoring(): void
119+
private function registerDashboard(): void
120120
{
121121
app('events')->listen(TaskCreated::class, function (TaskCreated $event) {
122-
if (CloudTasks::monitorDisabled()) {
122+
if (CloudTasks::dashboardDisabled()) {
123123
return;
124124
}
125125

126-
MonitoringService::make()->addToMonitor($event->queue, $event->task);
126+
DashboardService::make()->add($event->queue, $event->task);
127127
});
128128

129129
app('events')->listen(JobFailed::class, function (JobFailed $event) {
@@ -140,39 +140,39 @@ private function registerMonitoring(): void
140140
});
141141

142142
app('events')->listen(JobProcessing::class, function (JobProcessing $event) {
143-
if (!CloudTasks::monitorEnabled()) {
143+
if (!CloudTasks::dashboardEnabled()) {
144144
return;
145145
}
146146

147147
if ($event->job instanceof CloudTasksJob) {
148-
MonitoringService::make()->markAsRunning($event->job->uuid());
148+
DashboardService::make()->markAsRunning($event->job->uuid());
149149
}
150150
});
151151

152152
app('events')->listen(JobProcessed::class, function (JobProcessed $event) {
153-
if (!CloudTasks::monitorEnabled()) {
153+
if (!CloudTasks::dashboardEnabled()) {
154154
return;
155155
}
156156

157157
if ($event->job instanceof CloudTasksJob) {
158-
MonitoringService::make()->markAsSuccessful($event->job->uuid());
158+
DashboardService::make()->markAsSuccessful($event->job->uuid());
159159
}
160160
});
161161

162162
app('events')->listen(JobExceptionOccurred::class, function (JobExceptionOccurred $event) {
163-
if (!CloudTasks::monitorEnabled()) {
163+
if (!CloudTasks::dashboardEnabled()) {
164164
return;
165165
}
166166

167-
MonitoringService::make()->markAsError($event);
167+
DashboardService::make()->markAsError($event);
168168
});
169169

170170
app('events')->listen(JobFailed::class, function ($event) {
171-
if (!CloudTasks::monitorEnabled()) {
171+
if (!CloudTasks::dashboardEnabled()) {
172172
return;
173173
}
174174

175-
MonitoringService::make()->markAsFailed($event);
175+
DashboardService::make()->markAsFailed($event);
176176
});
177177
}
178178
}

src/MonitoringService.php renamed to src/DashboardService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
use Illuminate\Support\Facades\DB;
1212
use function Safe\json_decode;
1313

14-
class MonitoringService
14+
class DashboardService
1515
{
16-
public static function make(): MonitoringService
16+
public static function make(): DashboardService
1717
{
18-
return new MonitoringService();
18+
return new DashboardService();
1919
}
2020

2121
private function getTaskBody(Task $task): string
@@ -29,7 +29,7 @@ private function getTaskBody(Task $task): string
2929
return $httpRequest->getBody();
3030
}
3131

32-
public function addToMonitor(string $queue, Task $task): void
32+
public function add(string $queue, Task $task): void
3333
{
3434
$metadata = new TaskMetadata();
3535
$metadata->payload = $this->getTaskBody($task);

tests/CloudTasksMonitoringTest.php renamed to tests/CloudTasksDashboardTest.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
use Illuminate\Routing\Route;
77
use Illuminate\Routing\Router;
88
use Illuminate\Support\Carbon;
9-
use Illuminate\Support\Facades\Schema;
109
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksApi;
11-
use Stackkit\LaravelGoogleCloudTasksQueue\CloudTasksServiceProvider;
1210
use Stackkit\LaravelGoogleCloudTasksQueue\OpenIdVerificator;
1311
use Stackkit\LaravelGoogleCloudTasksQueue\StackkitCloudTask;
1412
use Tests\Support\FailingJob;
1513
use Tests\Support\SimpleJob;
1614

17-
class CloudTasksMonitoringTest extends TestCase
15+
class CloudTasksDashboardTest extends TestCase
1816
{
1917
/**
2018
* @test
@@ -243,7 +241,7 @@ public function it_returns_info_about_a_specific_task()
243241
/**
244242
* @test
245243
*/
246-
public function when_a_job_is_dispatched_it_will_be_added_to_the_monitor()
244+
public function when_a_job_is_dispatched_it_will_be_added_to_the_dashboard()
247245
{
248246
// Arrange
249247
CloudTasksApi::fake();
@@ -267,11 +265,11 @@ public function when_a_job_is_dispatched_it_will_be_added_to_the_monitor()
267265
/**
268266
* @test
269267
*/
270-
public function when_monitoring_is_disabled_jobs_will_not_be_added_to_the_monitor()
268+
public function when_dashboard_is_disabled_jobs_will_not_be_added_to_the_dashboard()
271269
{
272270
// Arrange
273271
CloudTasksApi::fake();
274-
config()->set('cloud-tasks.monitor.enabled', false);
272+
config()->set('cloud-tasks.dashboard.enabled', false);
275273

276274
// Act
277275
$this->dispatch(new SimpleJob());
@@ -308,7 +306,7 @@ public function when_a_job_is_scheduled_it_will_be_added_as_such()
308306
/**
309307
* @test
310308
*/
311-
public function when_a_job_is_running_it_will_be_updated_in_the_monitor()
309+
public function when_a_job_is_running_it_will_be_updated_in_the_dashboard()
312310
{
313311
// Arrange
314312
\Illuminate\Support\Carbon::setTestNow(now());
@@ -334,7 +332,7 @@ public function when_a_job_is_running_it_will_be_updated_in_the_monitor()
334332
/**
335333
* @test
336334
*/
337-
public function when_a_job_is_successful_it_will_be_updated_in_the_monitor()
335+
public function when_a_job_is_successful_it_will_be_updated_in_the_dashboard()
338336
{
339337
// Arrange
340338
\Illuminate\Support\Carbon::setTestNow(now());
@@ -360,7 +358,7 @@ public function when_a_job_is_successful_it_will_be_updated_in_the_monitor()
360358
/**
361359
* @test
362360
*/
363-
public function when_a_job_errors_it_will_be_updated_in_the_monitor()
361+
public function when_a_job_errors_it_will_be_updated_in_the_dashboard()
364362
{
365363
// Arrange
366364
\Illuminate\Support\Carbon::setTestNow(now());
@@ -387,7 +385,7 @@ public function when_a_job_errors_it_will_be_updated_in_the_monitor()
387385
/**
388386
* @test
389387
*/
390-
public function when_a_job_fails_it_will_be_updated_in_the_monitor()
388+
public function when_a_job_fails_it_will_be_updated_in_the_dashboard()
391389
{
392390
// Arrange
393391
\Illuminate\Support\Carbon::setTestNow(now());
@@ -422,7 +420,7 @@ public function when_a_job_fails_it_will_be_updated_in_the_monitor()
422420
public function test_publish()
423421
{
424422
// Arrange
425-
config()->set('cloud-tasks.monitor.enabled', true);
423+
config()->set('cloud-tasks.dashboard.enabled', true);
426424

427425
// Act & Assert
428426
$expectedPublishBase = dirname(__DIR__);
@@ -436,7 +434,7 @@ public function test_publish()
436434
/**
437435
* @test
438436
*/
439-
public function when_monitoring_is_enabled_it_adds_the_necessary_routes()
437+
public function when_dashboard_is_enabled_it_adds_the_necessary_routes()
440438
{
441439
// Act
442440
$routes = app(Router::class)->getRoutes();
@@ -452,23 +450,23 @@ public function when_monitoring_is_enabled_it_adds_the_necessary_routes()
452450
/**
453451
* @test
454452
*/
455-
public function when_monitoring_is_enabled_it_adds_the_necessary_migrations()
453+
public function when_dashboard_is_enabled_it_adds_the_necessary_migrations()
456454
{
457455
$this->assertTrue(in_array(dirname(__DIR__) . '/src/../migrations', app('migrator')->paths()));
458456
}
459457

460458
/**
461459
* @test
462460
*/
463-
public function when_monitoring_is_disabled_it_adds_the_necessary_migrations()
461+
public function when_dashboard_is_disabled_it_adds_the_necessary_migrations()
464462
{
465463
$this->assertEmpty(app('migrator')->paths());
466464
}
467465

468466
/**
469467
* @test
470468
*/
471-
public function when_monitoring_is_disabled_it_does_not_add_the_monitor_routes()
469+
public function when_dashboard_is_disabled_it_does_not_add_the_dashboard_routes()
472470
{
473471
// Act
474472
$routes = app(Router::class)->getRoutes();
@@ -484,7 +482,7 @@ public function when_monitoring_is_disabled_it_does_not_add_the_monitor_routes()
484482
/**
485483
* @test
486484
*/
487-
public function monitoring_is_password_protected()
485+
public function dashboard_is_password_protected()
488486
{
489487
// Arrange
490488
$this->defaultHeaders['Authorization'] = '';
@@ -533,7 +531,7 @@ public function there_is_a_login_endpoint()
533531
{
534532
// Arrange
535533
Carbon::setTestNow($now = now());
536-
config()->set('cloud-tasks.monitor.password', bcrypt('test123'));
534+
config()->set('cloud-tasks.dashboard.password', 'test123');
537535

538536
// Act
539537
$invalidPassword = $this->postJson('/cloud-tasks-api/login', ['password' => 'hey']);

0 commit comments

Comments
 (0)