It sounds like both of your Horizon instances are using the same Redis database and queue name, which is why jobs dispatched on one site are being picked up by both Horizon instances. To resolve this issue, you need to ensure that each site has its own unique queue configuration.
Here are the steps you can take to fix this issue:
-
Configure Separate Redis Databases or Prefixes: Each site should use a different Redis database or a unique prefix to prevent collision.
For example, in your
.envfile for each site, you can specify a different Redis database:Site A:
REDIS_DB=0Site B:
REDIS_DB=1Or use different prefixes:
Site A:
REDIS_PREFIX=site_a_database_Site B:
REDIS_PREFIX=site_b_database_ -
Unique Horizon Environments: Make sure that each site has a unique Horizon environment specified in the
config/horizon.phpconfiguration file.For example:
Site A:
'environments' => [ 'production' => [ // ... ], 'site_a' => [ 'supervisor-1' => [ 'connection' => 'redis', 'queue' => ['site_a_queue'], 'balance' => 'simple', 'processes' => 10, 'tries' => 3, ], ], ],Site B:
'environments' => [ 'production' => [ // ... ], 'site_b' => [ 'supervisor-1' => [ 'connection' => 'redis', 'queue' => ['site_b_queue'], 'balance' => 'simple', 'processes' => 10, 'tries' => 3, ], ], ], -
Run Horizon with the Correct Environment: When you start Horizon, make sure to specify the correct environment for each site.
For Site A:
php artisan horizon --environment=site_aFor Site B:
php artisan horizon --environment=site_b -
Dispatch Jobs to the Correct Queue: When dispatching jobs, make sure to specify the correct queue that corresponds to the site.
For Site A:
dispatch((new YourJob)->onQueue('site_a_queue'));For Site B:
dispatch((new YourJob)->onQueue('site_b_queue'));
By following these steps, you should be able to isolate the Horizon instances and queues for each site, preventing them from picking up each other's jobs. Make sure to restart the Horizon service after making these changes to apply the new configuration.