Absolutely, you can achieve this with Laravel Horizon by customizing the horizon.php configuration file on each server. Horizon allows you to define multiple "environments" or "supervisors" with different queue settings. The key is to have a different supervisor configuration on each server, so each one listens only to the queues you want.
Here's how you can do it:
1. Edit config/horizon.php on each server
On server1 (only process short-living queue):
'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['short-living'],
'balance' => 'auto',
'processes' => 3,
'tries' => 3,
],
],
On server2 and server3 (only process heavy-lifting queue):
'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => ['heavy-lifting'],
'balance' => 'auto',
'processes' => 3,
'tries' => 3,
],
],
You can adjust the number of processes and tries as needed.
2. (Optional) Use Environment-Specific Configuration
If you want to keep a single horizon.php file, you can use environment variables to determine which queues each server should process. For example:
'defaults' => [
'supervisor-1' => [
'connection' => 'redis',
'queue' => explode(',', env('HORIZON_QUEUES', 'default')),
'balance' => 'auto',
'processes' => 3,
'tries' => 3,
],
],
Then, set the environment variable on each server:
- On
server1:HORIZON_QUEUES=short-living - On
server2andserver3:HORIZON_QUEUES=heavy-lifting
3. Restart Horizon
After updating the configuration or environment variables, restart Horizon on each server:
php artisan horizon:terminate
Horizon will restart and pick up the new configuration.
Summary:
You can control which queues each server processes by customizing the queue setting in the Horizon supervisor configuration on each server. This is a common pattern for scaling and isolating different types of jobs in Laravel Horizon.
Let me know if you need a more detailed example or help with supervisor process management!