diff --git a/src/Commands/LaravelHorizonDoctorCommand.php b/src/Commands/LaravelHorizonDoctorCommand.php index 37dca9d..7dea6bd 100644 --- a/src/Commands/LaravelHorizonDoctorCommand.php +++ b/src/Commands/LaravelHorizonDoctorCommand.php @@ -12,8 +12,6 @@ class LaravelHorizonDoctorCommand extends Command public function handle(): int { - $this->info('Checking your Horizon configs...'); - $horizonConfigs = config('horizon.environments.production'); $default = config('horizon.defaults'); $queueConfigs = config('queue.connections'); @@ -27,6 +25,17 @@ public function handle(): int } } + $this->checkHorizonConfigs($horizonConfigs, $queueConfigs); + $this->checkDefaultQueuesAreProcessed($horizonConfigs, $queueConfigs); + $this->checkConnectionsAreUsedInHorizon($queueConfigs, $horizonConfigs); + + return self::SUCCESS; + } + + protected function checkHorizonConfigs(array $horizonConfigs, array $queueConfigs) + { + $this->info('Checking your Horizon configs...'); + foreach ($horizonConfigs as $key => $horizonConfig) { $errors = collect(); $this->info("Checking queue `{$key}`"); @@ -52,6 +61,7 @@ public function handle(): int if (isset($horizonConfig['timeout']) && $horizonConfig['timeout'] >= $queueConnection['retry_after']) { $errors[] = "`timeout` of configured horizon queue `{$key}` ({$horizonConfig['timeout']}) in config/horizon.php should be marginally bigger than the `retry_after` option of the queue connection `{$key}` ({$horizonConfig['timeout']}) set in config/queue.php"; } + if ($errors->count()) { $errors->each(fn ($error) => $this->error("- {$error}")); } else { @@ -60,11 +70,14 @@ public function handle(): int $this->comment(''); } + } + protected function checkConnectionsAreUsedInHorizon(array $queueConfigs, array $horizonConfigs): void + { $this->info('Running some global checks...'); // check that all queue connections are used in horizon - $redisQueues = collect($queueConfigs) + $redisQueueConnections = collect($queueConfigs) ->filter(fn ($queue) => $queue['driver'] === 'redis') ->keys(); $usedConnectionsInHorizon = collect($horizonConfigs) @@ -72,7 +85,7 @@ public function handle(): int ->unique() ->values(); - $diff = $redisQueues->diff($usedConnectionsInHorizon); + $diff = $redisQueueConnections->diff($usedConnectionsInHorizon); if (count($diff) > 0) { $diff = $diff->implode(','); @@ -80,7 +93,37 @@ public function handle(): int } else { $this->info('- Everything looks good!'); } + } - return self::SUCCESS; + protected function checkDefaultQueuesAreProcessed(array $horizonConfigs, array $queueConfigs) + { + $this->info('Checking your Queue configs...'); + + $redisQueueConnections = collect($queueConfigs) + ->filter(fn ($queue) => $queue['driver'] === 'redis'); + + foreach ($redisQueueConnections as $connectionName => $queueConfig) { + $this->info("Checking connection `{$connectionName}`"); + $errors = collect(); + + // check that default queue is processed by horizon + $processedQueuesInHorizon = collect($horizonConfigs) + ->map(fn ($queue) => $queue['queue']) + ->flatten() + ->unique() + ->values(); + $defaultQueue = $queueConfig['queue']; + if (! $processedQueuesInHorizon->contains($defaultQueue)) { + $errors[] = "Default queue `{$defaultQueue}` of connection `{$connectionName}` will not be processed by any worker set in config/horizon.php"; + } + + if ($errors->count()) { + $errors->each(fn ($error) => $this->error("- {$error}")); + } else { + $this->info('- Everything looks good!'); + } + + $this->comment(''); + } } }