Laravel通知作业由主管运行多次

Laravel通知作业由主管运行多次,laravel,centos,supervisord,Laravel,Centos,Supervisord,所以我有一个laravel项目正在生产中运行,并使用主管处理作业和通知 问题是,在supervisor运行几个小时后,它开始发送重复的通知,而且它运行的时间越长,发送通知的次数就越多(相同的通知发送了4次) 我的通知如下所示: class MessageNotification extends Notification implements ShouldQueue { use Queueable; public function __construct($opts = [])

所以我有一个laravel项目正在生产中运行,并使用主管处理作业和通知

问题是,在supervisor运行几个小时后,它开始发送重复的通知,而且它运行的时间越长,发送通知的次数就越多(相同的通知发送了4次)

我的通知如下所示:

class MessageNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct($opts = [])
    {
        $this->connection = 'database';
        $this->queue = 'sendMail';
    }

    public function via($notifiable)
    {
        return ['mail', 'database', 'broadcast'];
    }

    public function toMail($notifiable)
    {
        $mesg = (new MailMessage)
            // ... defining message stuff

        return $mesg;
    }

    public function toArray($notifiable)
    {
        return [
          // .. defining array stuff
        ];
    }

    public function toBroadcast($notifiable){
        return (new BroadcastMessage($this->toArray($notifiable)));
    }
}
return [
    'default' => env('QUEUE_CONNECTION', 'sync'),

    'connections' => [

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

        'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            'queue' => 'sendMail',
            'retry_after' => 90,
        ],
    ],


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

];
[program:laravel-worker]
command=php /app/artisan queue:work database --queue=sendMail --sleep=3 --tries=3 --timeout=75
process_name=%(program_name)s_%(process_num)02d
numprocs=8
priority=999
autostart=true
autorestart=true
startsecs=1
startretries=3
user=yastechco
redirect_stderr=true
stdout_logfile=/app/worker.log
我的队列配置如下所示:

class MessageNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct($opts = [])
    {
        $this->connection = 'database';
        $this->queue = 'sendMail';
    }

    public function via($notifiable)
    {
        return ['mail', 'database', 'broadcast'];
    }

    public function toMail($notifiable)
    {
        $mesg = (new MailMessage)
            // ... defining message stuff

        return $mesg;
    }

    public function toArray($notifiable)
    {
        return [
          // .. defining array stuff
        ];
    }

    public function toBroadcast($notifiable){
        return (new BroadcastMessage($this->toArray($notifiable)));
    }
}
return [
    'default' => env('QUEUE_CONNECTION', 'sync'),

    'connections' => [

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

        'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            'queue' => 'sendMail',
            'retry_after' => 90,
        ],
    ],


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

];
[program:laravel-worker]
command=php /app/artisan queue:work database --queue=sendMail --sleep=3 --tries=3 --timeout=75
process_name=%(program_name)s_%(process_num)02d
numprocs=8
priority=999
autostart=true
autorestart=true
startsecs=1
startretries=3
user=yastechco
redirect_stderr=true
stdout_logfile=/app/worker.log
我的主管配置如下:

class MessageNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public function __construct($opts = [])
    {
        $this->connection = 'database';
        $this->queue = 'sendMail';
    }

    public function via($notifiable)
    {
        return ['mail', 'database', 'broadcast'];
    }

    public function toMail($notifiable)
    {
        $mesg = (new MailMessage)
            // ... defining message stuff

        return $mesg;
    }

    public function toArray($notifiable)
    {
        return [
          // .. defining array stuff
        ];
    }

    public function toBroadcast($notifiable){
        return (new BroadcastMessage($this->toArray($notifiable)));
    }
}
return [
    'default' => env('QUEUE_CONNECTION', 'sync'),

    'connections' => [

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

        'database' => [
            'driver' => 'database',
            'table' => 'jobs',
            'queue' => 'sendMail',
            'retry_after' => 90,
        ],
    ],


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

];
[program:laravel-worker]
command=php /app/artisan queue:work database --queue=sendMail --sleep=3 --tries=3 --timeout=75
process_name=%(program_name)s_%(process_num)02d
numprocs=8
priority=999
autostart=true
autorestart=true
startsecs=1
startretries=3
user=yastechco
redirect_stderr=true
stdout_logfile=/app/worker.log
在本地机器上运行开发时不会发生这种情况


如果重要的话,生产服务器运行在CentOS 7.6.1810和Supervisord 3.1.4上

我最终将redis配置为我的队列适配器,它似乎已经解决了这个问题

发送重复通知的间隔有多远?也许这项工作花费了很长时间,这会引发重试。在我的日志中,它会在完全相同的时间引导他们处理:App\Notifications\MessageNotification[2019-08-01 11:25:02][253]处理:App\Notifications\MessageNotification[2019-08-01 11:25:03][254]处理:App\Notifications\MessageNotification可能是数据库驱动程序。看起来其他人也有类似的问题:我确实遇到过,但添加redis会增加应用程序的复杂性,我希望不需要这样做。