Max Attempts Exceeded 异常队列laravel [英] Max Attempts Exceeded Exception queue laravel

查看:436
本文介绍了Max Attempts Exceeded 异常队列laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个应用程序来向多个用户发送电子邮件,但在处理大量收件人时遇到问题.

I have created an application to send e-mails to more than one user but I am facing a problem when dealing with a large number of recipients.

错误出现在 failed_jobs 表中

Illuminate\Queue\MaxAttemptsExceededException: App\Jobs\ESender has been attempted too many times or run too long. The job may have previously timed out. in D:\EmailSender\vendor\laravel\framework\src\Illuminate\Queue\Worker.php:649

这是failed_jobs表中的payload

{"uuid":"ff988083-c1da-4d20-a2e3-c2a10e154c79","timeout":9000,"id":"j2Lz0Ro0bkJpqwxKWTxC3Tiii71iE6Cm","data":{"command":"O:16:\"App\\Jobs\\ESender\":13:{s:7:\"timeout\";i:9000;s:12:\"receiver_obj\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:12:\"App\\Receiver\";s:2:\"id\";i:6;s:9:\"relations\";a:0:{}s:10:\"connection\";s:5:\"mysql\";}s:16:\"sender_all_hosts\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:15:\"App\\SenderHosts\";s:2:\"id\";a:4:{i:0;i:1;i:1;i:2;i:2;i:3;i:3;i:4;}s:9:\"relations\";a:0:{}s:10:\"connection\";s:5:\"mysql\";}s:11:\"message_obj\";O:45:\"Illuminate\\Contracts\\Database\\ModelIdentifier\":4:{s:5:\"class\";s:12:\"App\\Messages\";s:2:\"id\";i:36;s:9:\"relations\";a:0:{}s:10:\"connection\";s:5:\"mysql\";}s:7:\"counter\";i:1;s:3:\"job\";N;s:10:\"connection\";N;s:5:\"queue\";N;s:15:\"chainConnection\";N;s:10:\"chainQueue\";N;s:5:\"delay\";N;s:10:\"middleware\";a:0:{}s:7:\"chained\";a:0:{}}","commandName":"App\\Jobs\\ESender"},"displayName":"App\\Jobs\\ESender","timeoutAt":1594841911,"maxExceptions":null,"maxTries":null,"job":"Illuminate\\Queue\\CallQueuedHandler@call","delay":null,"attempts":1}

在此处查看 cmd 错误.

部分代码:

#1

class ESender implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;


    /**
     * The number of times the job may be attempted.
     *
     * @var int
     */
    public $tries = 100;

    /**
     * The number of seconds the job can run before timing out.
     *
     * @var int
     */
    public $timeout = 9999999;

     ...more code...
}

#2

public function handle(){
    Redis::throttle('key')->allow(1)->every(20)->then(function () {
         //send email
           ..... more code .....

        }, function () {
            // Could not obtain lock...
            return $this->release(10);
        });
    }

这是我的配置:

queue.php:

'redis' => [
            'driver' => 'redis',
            'connection' => 'default',
            'queue' => env('REDIS_QUEUE', 'default'),
            'retry_after' => 9000,
            'block_for' => null,
        ],

.env

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=database
SESSION_DRIVER=file
SESSION_LIFETIME=300
REDIS_CLIENT = predis
REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379
QUEUE_DRIVER=database

推荐答案

您在作业中设置了 timeout,但此超时大于 retry_after 中的值您已在此配置中定义.

You set a timeout in your job, but this timeout is larger than the value in retry_after which you have defined in the this config.

参见 https://laravel.com/docs/7.x/queues#job-expirations-and-timeouts

有一个明确的警告:

--timeout 值应始终至少比您的 retry_after 配置值短几秒.这将确保在重试作业之前总是杀死处理给定作业的工人.如果您的 --timeout 选项比您的 retry_after 配置值长,您的作业可能会被处理两次.

The --timeout value should always be at least several seconds shorter than your retry_after configuration value. This will ensure that a worker processing a given job is always killed before the job is retried. If your --timeout option is longer than your retry_after configuration value, your jobs may be processed twice.

您可以为长时间运行的作业定义一个新连接,并在作业上设置此连接(分派到特定连接),而不是使用 timeout.

You could define a new connection for long running jobs, and set this connection on the job (dispatch to specific connection), instead of using the timeout.

这篇关于Max Attempts Exceeded 异常队列laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆