To address the issue of Laravel Horizon processing jobs across both your Main and Staging sites on the same server, you need to ensure that each site is using a separate queue connection and Redis database. This will isolate the job processing for each site. Here’s how you can achieve this:
-
Separate Redis Databases: Ensure that each site is configured to use a different Redis database. You can do this by setting different
REDIS_DATABASEvalues in the.envfiles for each site.For the Main site, in the
.envfile:REDIS_DATABASE=0For the Staging site, in the
.envfile:REDIS_DATABASE=1 -
Configure Queue Connections: Define separate queue connections for each site in the
config/queue.phpfile. You can create custom connections for each environment.Example configuration in
config/queue.php:'connections' => [ 'main_site' => [ 'driver' => 'redis', 'connection' => 'default', 'queue' => env('MAIN_QUEUE', 'default'), 'retry_after' => 90, ], 'staging_site' => [ 'driver' => 'redis', 'connection' => 'default', 'queue' => env('STAGING_QUEUE', 'default'), 'retry_after' => 90, ], ], -
Update Horizon Configuration: Ensure that each site’s Horizon configuration is using the correct queue connection. Update the
config/horizon.phpfile for each site to specify the correct connection.For the Main site:
'environments' => [ 'production' => [ 'supervisor-1' => [ 'connection' => 'main_site', 'queue' => ['default'], 'balance' => 'auto', 'processes' => 3, 'tries' => 3, ], ], ],For the Staging site:
'environments' => [ 'staging' => [ 'supervisor-1' => [ 'connection' => 'staging_site', 'queue' => ['default'], 'balance' => 'auto', 'processes' => 3, 'tries' => 3, ], ], ], -
Restart Horizon: After making these changes, restart Horizon on both sites to apply the new configurations. You can do this via the command line:
php artisan horizon:terminateThis command will gracefully terminate the current Horizon processes, and they will restart automatically with the new configuration.
By following these steps, you should be able to isolate the job processing for each site, ensuring that jobs dispatched for the Main site do not run on the Staging site and vice versa.