troovers's avatar

Redis queue & Horizon

Hi guys,

I've upgraded to Laravel 5.5 this week and installed Horizon to monitor my queues. For that to work, I had to change the queue driver from database to Redis. I didn't expect much trouble caused by that switch. I was wrong, unfortunately.

I've managed to get Horizon up and running (easily) and configured the Redis queue driver. In my local environment, everything is working fine! Then I went live and I noticed that around 50% of my jobs aren't being executed. When I check the Horizon dashboard, about 50% of the jobs has a red cross behind them, but didn't fail. So, they didn't even fire. This doesn't happen to a specific job, it just happens randomly. For instance: sometimes a job succeeds five times in a row, and then isn't executed for three times. Pretty annoying as you can guess. But, because I got no errors whatsoever, debugging is a pain in the ass. Maybe you can help me with the problem. Below you'll find my configs.

config/queue.php

'connections' => [

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

    ],

config/horizon.php

'environments' => [
        'production' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['default'],
                'balance' => 'auto',
                'processes' => 10,
                'tries' => 3,
            ] 
        ],

        'dev' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['default'],
                'balance' => 'simple',
                'processes' => 3,
                'tries' => 3,
            ],
        ],
    ],

Thanks in advance!

Thomas

0 likes
8 replies
rossuhms's avatar

Hi mate,

Bit of a weird one really. Have you configured a process monitor (e.g. Supervisor) to watch the php artisan horizon command and restart it if it quits?

If the jobs aren't being executed at all, and intermittently failing then their must be something wrong with your redis configuration, or the actual code that's being executed with the job.

I take it that you are unable to find any exceptions being thrown in the laravel.log file? If not then you could set up a service like Sentry or Bugsnag to monitor your application for any errors or exceptions being thrown in production to allow you to debug the problem in live time.

troovers's avatar

Hi, thanks for your reply. I do indeed have a daemon running on Laravel Forge to keep the horizon command active.

The logs are not showing any errors, or info lines regarding this. Sentry is already active in the project, but does also not return an error.

It's indeed a real hard one..

mhankins's avatar

I'm not sure why you have two supervisor configs in production.. I would try just one.

troovers's avatar

I tried one or two supervisor configs, didn't make a difference. I hadn't removed it yet.

mhankins's avatar

Strange, I don't have any horizon apps currently deployed on Forge, but I do have a large app in production on Ubuntu. It works as expected with this config.

    'environments' => [
        'production' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['default', 'import', 'order'],
                'balance' => 'auto',
                'processes' => 10,
                'tries' => 3,
            ],
        ],

        'local' => [
            'supervisor-1' => [
                'connection' => 'redis',
                'queue' => ['default', 'import', 'order'],
                'balance' => 'auto',
                'processes' => 10,
                'tries' => 3,
            ],
        ],
    ],

On failed jobs are you able to click them for further details? We're all just going to be stabbing in the dark without some type of error :(

troovers's avatar

We do have the same config indeed. I know we're stabbing in the dark, but I've got no more information to provide you, than I've already given you.

Horizon displays all of the job's I'm passing on to the queue. When a job succeeds, I can't click on the job to view the details. But that's not a problem, the job succeeds anyway.

When a job failed, I can click it to view errors. When a job however isn't executed at all, I can in fact click it, but it doesn't display any errors. It just says:

ID: 38
On: default
Failed Time: 1970-01-01 00:59:59

And it displays the job parameters.

troovers's avatar
troovers
OP
Best Answer
Level 1

Thanks for your help guys, I just found the solution! I had two sites running on my Forge server. They both used the redis queue driver and both added jobs to the 'default' queue. This led to the fact that the jobs are executed by one of the two sites. And because the other site did not have an active artisan horizon command, the jobs would not be executed. It thus seemed that site1 was handling the job, but in fact it was site2.

Renaming the queue of one of the applications solved the problem, the jobs are now added to the running horizon command of the correct application.

Please or to participate in this conversation.