Search code examples
phplaravelqueueforge

Multiple queues on the same server with Laravel Forge


I've three of the same Laravel Application running but on different environments using Laravel Forge.

Let's say these are the three sites:

  • site.com (production)
  • staging.site.com (staging)
  • dev.site.com (develop)

On the production site I run Laravel Horizon to monitor the queues for the production site.

When I run a password reset on my dev.site.com the email is not sending to the user because of Exception which happens in queue.

Illuminate\Database\Eloquent\ModelNotFoundException: No query results for model [App\Models\User]. in /home/forge/site.com/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Builder.php:412

If you look closely in the error you'll see that the errors occurred on the site.com production environment. So an email is put on queue in the develop environment, but is executed in the production environment.

This is my queue.php config:

<?php

return [

    'default' => env('QUEUE_DRIVER', 'high'),

    'connections' => [

        'sync' => [
            'driver' => 'sync',
        ],

        'high' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => 'default',
            'retry_after' => 90,
        ],

        'medium' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => 'default',
            'retry_after' => 90,
        ],

        'low' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => 'default',
            'retry_after' => 90,
        ],

    ],

    'failed' => [
        'database' => env('DB_CONNECTION', 'mysql'),
        'table' => 'failed_jobs',
    ],

];

These are the queue settings on all three environments on Forge:

Laravel Forge Queue config

Is this normal behaviour? Or is there something which I'm doing wrong?


Solution

  • Sounds like youre using the same queue driver across all the sites and they have identical configs, right? If that's the case you're pooling across all three sites which is "contaminating" one with the others. You need to alter the configs on each so they have individual queues, that way it will keep them separated. You can even have separate redis, database, memcache, etc instances. In fact I'd recommend that you do for production at least.