【发布时间】:2019-08-01 17:55:21
【问题描述】:
所以我有一个 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
在我的本地机器上的开发中运行时不会发生这种情况。
如果重要的话,生产服务器在 CentOS 7.6.1810 和 Supervisord 3.1.4 上运行
【问题讨论】:
-
重复通知的发送距离有多远?也许这项工作需要很长时间,并且开始重试。
-
在我的日志中,它会同时给他们穿鞋
[2019-08-01 11:25:02][253] Processing: App\Notifications\MessageNotification [2019-08-01 11:25:02][253] Processing: App\Notifications\MessageNotification [2019-08-01 11:25:03][254] Processing: App\Notifications\MessageNotification -
可能是数据库驱动程序。看起来其他人也有类似的问题:reddit.com/r/laravel/comments/9xbbn7/…
-
我确实遇到过,但是添加 redis 会增加应用程序的复杂性,我希望不需要这样做。
标签: laravel centos supervisord