简体   繁体   English

Laravel 地平线排队作业因 MaxAttemptsExceededException 而失败

[英]Laravel horizon queued jobs fails with MaxAttemptsExceededException

I dispatch jobs to do some work on my horizon queue.我分派工作在我的地平线队列上做一些工作。 It appears the same jobs are always failing with 60s runtime, which to me looks like a timeout issue:似乎相同的作业总是以 60 秒的运行时间失败,在我看来,这似乎是一个超时问题:

在此处输入图片说明

I dispatch around 10 jobs via a cron schedule, and these 4 are always failing.我通过 cron 计划调度了大约 10 个作业,而这 4 个总是失败。

This is my config/horizon.php (just the interesting parts):这是我的config/horizon.php (只是有趣的部分):

<?php

use Illuminate\Support\Str;

return [

    'waits' => [
        'redis:default' => 60,
    ],

    'memory_limit' => 512,

    'defaults' => [
        'my-app-queue' => [
            'connection' => 'redis',
            'queue' => ['default'],
            'balance' => 'auto',
            'minProcesses' => 1,
            'maxProcesses' => 1,
            'balanceMaxShift' => 1,
            'balanceCooldown' => 3,
            'memory' => 512,
            'tries' => 3,
            'nice' => 0,
            'timeout' => 300,
        ],
    ],

    'environments' => [
        'production' => [
            'my-app-queue' => [
                'maxProcesses' => 10,
            ],
        ],

        'local' => [
            'my-app-queue' => [
                'maxProcesses' => 10,
            ],
        ],
    ],
];

As you can see, I have set a timeout of 300 seconds, but the job always failing at 60 second mark.如您所见,我已将超时设置为 300 秒,但作业总是在 60 秒标记处失败。

I start the horizon queue processor in my docker container with this entrypoint command: php /path/to/artisan horizon我使用以下入口点命令在我的 docker 容器中启动地平线队列处理器: php /path/to/artisan horizon

To debug the issue, I instantiated the job class manually to see where it is failing like this:为了调试问题,我手动实例化了作业类以查看它在哪里失败,如下所示:

    $test = new DownloadBlockedIPFeed(8);
    $test->handle();
    exit('Done');

This does seem to be taking longer than 60 seconds, but it does complete.这似乎需要超过 60 秒,但它确实完成了。

So my question is - how do you properly set the timeout for laravel horizon?所以我的问题是 - 你如何正确设置 Laravel 地平线的超时时间?

I am using laravel 8.x and latest version of the horizon package.我正在使用 laravel 8.x 和最新版本的地平线包。

It may also be the balance strategy.这也可能是平衡策略。 I've found that If I set the 'balance' option to 'auto', it gives the MaxAttemptsExceededException errors.我发现如果我将“平衡”选项设置为“自动”,则会出现 MaxAttemptsExceededException 错误。 changing it to 'simple' or 'false' seems to be the solution.将其更改为“简单”或“假”似乎是解决方案。

Not sure if this is a bug, but I don't think this is expected behavior either.不确定这是否是一个错误,但我认为这也不是预期的行为。 I've seen jobs that where executed (logging in the handle method of the job) but killed off in the middle for retry.我见过执行的作业(登录作业的句柄方法)但在中间被杀死以进行重试。

Check the value for --timeout= in the spawned horizon:supervisor process.检查生成的horizon:supervisor进程中--timeout=的值。 If this is 60 seconds, adjust the timeout value in config/horizon.php .如果这是 60 秒,请在config/horizon.php调整timeout值。

Also check retry_after in config/queue.php .同时检查retry_afterconfig/queue.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM