update: queue

This commit is contained in:
tokumeikoi 2022-07-29 16:20:01 +08:00
parent 3fdd6ac30c
commit 1d62f87efc
4 changed files with 64 additions and 6 deletions

View File

@ -19,7 +19,12 @@ use App\Models\StatServer;
use Illuminate\Support\Facades\Cache; use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Http;
use Laravel\Horizon\Contracts\JobRepository;
use Laravel\Horizon\Contracts\MasterSupervisorRepository; use Laravel\Horizon\Contracts\MasterSupervisorRepository;
use Laravel\Horizon\Contracts\MetricsRepository;
use Laravel\Horizon\Contracts\SupervisorRepository;
use Laravel\Horizon\Contracts\WorkloadRepository;
use Laravel\Horizon\WaitTimeCalculator;
class SystemController extends Controller class SystemController extends Controller
{ {
@ -33,9 +38,11 @@ class SystemController extends Controller
]); ]);
} }
public function getQueueStatus() public function getQueueWorkload(WorkloadRepository $workload)
{ {
return response([
'data' => collect($workload->get())->sortBy('name')->values()->toArray()
]);
} }
protected function getScheduleStatus():bool protected function getScheduleStatus():bool
@ -53,5 +60,56 @@ class SystemController extends Controller
return $master->status === 'paused'; return $master->status === 'paused';
}) ? false : true; }) ? false : true;
} }
public function getQueueStats()
{
return response([
'data' => [
'failedJobs' => app(JobRepository::class)->countRecentlyFailed(),
'jobsPerMinute' => app(MetricsRepository::class)->jobsProcessedPerMinute(),
'pausedMasters' => $this->totalPausedMasters(),
'periods' => [
'failedJobs' => config('horizon.trim.recent_failed', config('horizon.trim.failed')),
'recentJobs' => config('horizon.trim.recent'),
],
'processes' => $this->totalProcessCount(),
'queueWithMaxRuntime' => app(MetricsRepository::class)->queueWithMaximumRuntime(),
'queueWithMaxThroughput' => app(MetricsRepository::class)->queueWithMaximumThroughput(),
'recentJobs' => app(JobRepository::class)->countRecent(),
'status' => $this->getHorizonStatus(),
'wait' => collect(app(WaitTimeCalculator::class)->calculate())->take(1),
]
]);
}
/**
* Get the total process count across all supervisors.
*
* @return int
*/
protected function totalProcessCount()
{
$supervisors = app(SupervisorRepository::class)->all();
return collect($supervisors)->reduce(function ($carry, $supervisor) {
return $carry + collect($supervisor->processes)->sum();
}, 0);
}
/**
* Get the number of master supervisors that are currently paused.
*
* @return int
*/
protected function totalPausedMasters()
{
if (! $masters = app(MasterSupervisorRepository::class)->all()) {
return 0;
}
return collect($masters)->filter(function ($master) {
return $master->status === 'paused';
})->count();
}
} }

View File

@ -113,8 +113,8 @@ class AdminRoute
$router->post('/payment/show', 'Admin\\PaymentController@show'); $router->post('/payment/show', 'Admin\\PaymentController@show');
// System // System
$router->get ('/system/getSystemStatus', 'Admin\\SystemController@getSystemStatus'); $router->get ('/system/getSystemStatus', 'Admin\\SystemController@getSystemStatus');
$router->get ('/system/getQueueStats', '\\Laravel\\Horizon\\Http\\Controllers\\DashboardStatsController@index'); $router->get ('/system/getQueueStats', 'Admin\\SystemController@getQueueStats');
$router->get ('/system/getQueueWorkload', '\\Laravel\\Horizon\\Http\\Controllers\\WorkloadController@index'); $router->get ('/system/getQueueWorkload', 'Admin\\SystemController@getQueueWorkload');
$router->get ('/system/getQueueMasters', '\\Laravel\\Horizon\\Http\\Controllers\\MasterSupervisorController@index'); $router->get ('/system/getQueueMasters', '\\Laravel\\Horizon\\Http\\Controllers\\MasterSupervisorController@index');
// Theme // Theme
$router->get ('/theme/getThemes', 'Admin\\ThemeController@getThemes'); $router->get ('/theme/getThemes', 'Admin\\ThemeController@getThemes');

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long