You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pixelfed/app/Providers/HorizonServiceProvider.php

50 lines
1.2 KiB
PHTML

<?php
namespace App\Providers;
use Illuminate\Support\Facades\Gate;
9 months ago
use Laravel\Horizon\Horizon;
use Laravel\Horizon\HorizonApplicationServiceProvider;
class HorizonServiceProvider extends HorizonApplicationServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
parent::boot();
Split Horizon into priority-based supervisors, add balanceCooldown and notification routing All 15 queues previously ran through one auto-balanced supervisor. Horizon's `balance: auto` does not honor queue array order for priority, so despite queue names implying priority ('high' vs 'low'), a burst on any one queue could starve any other sharing that supervisor - e.g. a burst of mmo (image/video optimization, 23 dispatch sites, CPU/IO heavy) could delay high-queue DM/follow delivery just as easily as it could delay low-queue background work. Split into 4 supervisors grouped by actual job characteristics (checked via grep across every ->onQueue() call site, not guessed): - supervisor-priority: high, inbox, pushnotify, follow, default, shared - user-facing federation/DM/notification delivery. - supervisor-fanout: feed, story, groups - bursty timeline/story fanout writes triggered by posts, likes, and follows. - supervisor-media: mmo - image/video optimize/resize/thumbnail. Runs a fixed worker pool (balance: false) instead of auto-scaling, so it can't claim workers away from the other pools under load. - supervisor-background: low, delete, adelete, move, intbg - imports, crawling, account deletion/migration; not time-sensitive. Moved the shared supervisor shape into `defaults` (keyed per supervisor name, per Horizon's own merge behavior) so `environments` only needs to override what actually differs, instead of each environment fully redefining supervisor-1 from scratch. Existing env vars (HORIZON_MAX_PROCESSES, HORIZON_MIN_PROCESSES, HORIZON_BALANCE_STRATEGY, HORIZON_SUPERVISOR_*) keep governing the priority supervisor for continuity with existing deployments; the three new supervisors get their own HORIZON_*_MAX_PROCESSES vars with conservative defaults. Also: - Added balanceCooldown: 3 explicitly (previously relied on SupervisorOptions' own constructor default of the same value - behavior is unchanged, just no longer implicit). - Wired LongWaitDetected notification routing (Horizon::routeMailNotificationsTo/routeSlackNotificationsTo) to new optional config('horizon.notification_routing') keys, sourced from env vars. Previously these were hardcoded, commented-out examples with nowhere to actually alert on the `waits` thresholds already configured below. Verified by actually starting `php artisan horizon` and inspecting `horizon:supervisors`: all 4 supervisors registered with exactly the intended queues, supervisor-media correctly running fixed (non-auto) balancing. Cross-checked every ->onQueue() call site in app/ against the new supervisor queue lists - exact match, no queue dropped or duplicated. Full test suite (715/715) and Larastan clean.
2 weeks ago
if ($mailTo = config('horizon.notification_routing.mail_to')) {
Horizon::routeMailNotificationsTo($mailTo);
}
if ($slackWebhook = config('horizon.notification_routing.slack_webhook_url')) {
Horizon::routeSlackNotificationsTo(
$slackWebhook,
config('horizon.notification_routing.slack_channel')
);
}
9 months ago
if (config('horizon.darkmode') == true) {
Horizon::night();
}
}
/**
* Register the Horizon gate.
*
* This gate determines who can access Horizon in non-local environments.
*
* @return void
*/
protected function gate()
{
Gate::define('viewHorizon', function ($user) {
return $user->is_admin == true;
});
}
}