Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.x] Ability to see which masters are paused and only show paused if everything is paused #929

Merged
merged 3 commits into from
Nov 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions resources/js/screens/dashboard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@
</svg>

<h4 class="mb-0 ml-2">{{ {running: 'Active', paused: 'Paused', inactive:'Inactive'}[stats.status] }}</h4>
<small v-if="stats.status == 'running' && stats.pausedMasters > 0" class="mb-0 ml-2">({{ stats.pausedMasters }} paused)</small>
</div>
</div>
</div>
Expand Down Expand Up @@ -293,6 +294,14 @@
<div class="card mt-4" v-for="worker in workers" :key="worker.name">
<div class="card-header d-flex align-items-center justify-content-between">
<h5>{{ worker.name }}</h5>

<svg v-if="worker.status == 'running'" class="fill-success" viewBox="0 0 20 20" style="width: 1.5rem; height: 1.5rem;">
<path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32zM6.7 9.29L9 11.6l4.3-4.3 1.4 1.42L9 14.4l-3.7-3.7 1.4-1.42z"></path>
</svg>

<svg v-if="worker.status == 'paused'" class="fill-warning" viewBox="0 0 20 20" style="width: 1.5rem; height: 1.5rem;">
<path d="M2.93 17.07A10 10 0 1 1 17.07 2.93 10 10 0 0 1 2.93 17.07zm12.73-1.41A8 8 0 1 0 4.34 4.34a8 8 0 0 0 11.32 11.32zM7 6h2v8H7V6zm4 0h2v8h-2V6z"/>
</svg>
</div>

<table class="table table-hover table-sm mb-0">
Expand Down
19 changes: 18 additions & 1 deletion src/Http/Controllers/DashboardStatsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public function index()
'failedJobs' => app(JobRepository::class)->countRecentlyFailed(),
'recentJobs' => app(JobRepository::class)->countRecent(),
'status' => $this->currentStatus(),
'pausedMasters' => $this->countPausedMasters(),
'wait' => collect(app(WaitTimeCalculator::class)->calculate())->take(1),
'periods' => [
'failedJobs' => config('horizon.trim.recent_failed', config('horizon.trim.failed')),
Expand Down Expand Up @@ -58,8 +59,24 @@ protected function currentStatus()
return 'inactive';
}

return collect($masters)->contains(function ($master) {
return collect($masters)->every(function ($master) {
return $master->status === 'paused';
}) ? 'paused' : 'running';
}

/**
* Get paused masters.
*
* @return int
*/
protected function countPausedMasters()
{
if (! $masters = app(MasterSupervisorRepository::class)->all()) {
return 0;
}

return collect($masters)->filter(function ($master) {
return $master->status === 'paused';
})->count();
}
}
23 changes: 22 additions & 1 deletion tests/Controller/DashboardStatsControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function test_paused_status_is_reflected_if_all_master_supervisors_are_pa
$masters = Mockery::mock(MasterSupervisorRepository::class);
$masters->shouldReceive('all')->andReturn([
(object) [
'status' => 'running',
'status' => 'paused',
],
(object) [
'status' => 'paused',
Expand All @@ -89,4 +89,25 @@ public function test_paused_status_is_reflected_if_all_master_supervisors_are_pa
'status' => 'paused',
]);
}

public function test_paused_status_isnt_reflected_if_not_all_master_supervisors_are_paused()
{
$masters = Mockery::mock(MasterSupervisorRepository::class);
$masters->shouldReceive('all')->andReturn([
(object) [
'status' => 'running',
],
(object) [
'status' => 'paused',
],
]);
$this->app->instance(MasterSupervisorRepository::class, $masters);

$response = $this->actingAs(new Fakes\User)
->get('/horizon/api/stats');

$response->assertJson([
'status' => 'running',
]);
}
}